Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/igorkasyanchuk/execution_time

How fast is your code? See it directly in Rails console.
https://github.com/igorkasyanchuk/execution_time

performance pry rails rails-application rails-gem ruby ruby-on-rails

Last synced: about 1 month ago
JSON representation

How fast is your code? See it directly in Rails console.

Lists

README

        

# ExecutionTime

[![Listed on OpenSource-Heroes.com](https://opensource-heroes.com/badge-v1.svg)](https://opensource-heroes.com/r/igorkasyanchuk/execution_time)

Monitor execution time and other metrics directly in `rails console`, similar to what you see after each request.

`[METRICS] Completed in 908.3ms | Allocations: 2894 | ActiveRecord: 0.9ms (queries: 13)`

## Usage

Just add this gem to the Gemfile and start `rails c`. After this try to do something like `User.first`.

If you want to measure few lines of code just wrap it with `begin/end`:

```ruby
[4] pry(main)> begin
[4] pry(main)* User.first.first_name.size
[4] pry(main)* a = User.count + 1
[4] pry(main)* b = User.second.last_name.size
[4] pry(main)* end
User Load (0.4ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT $1 [["LIMIT", 1]]
(3.6ms) SELECT COUNT(*) FROM "users"
User Load (0.3ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT $1 OFFSET $2 [["LIMIT", 1], ["OFFSET", 1]]
[METRICS] Completed in 6.8ms | Allocations: 839 | ActiveRecord: 4.3ms (queries: 3)
=> 5
```

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'execution_time'
```

## First run

Sometime you can see that there are more SQL queries or allocated objects because Ruby is just loading objects in memory or verifying connection to the DB.

## How to disable/enable metrics output in the console

If you need to disable gem in the console you can do it by `ExecutionTime.disable!`. And later enable with `ExecutionTime.enable!`.

By default gem is enabled.

## Contributing

You are welcome to contribute.

## Contributos

- https://github.com/nbulaj

## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

[](https://www.railsjazz.com/?utm_source=github&utm_medium=bottom&utm_campaign=execution_time)