Execution Time Save

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

Project README

ExecutionTime

Listed on OpenSource-Heroes.com

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:

[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:

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

License

The gem is available as open source under the terms of the MIT License.

Open Source Agenda is not affiliated with "Execution Time" Project. README Source: igorkasyanchuk/execution_time
Stars
114
Open Issues
1
Last Commit
9 months ago
License
MIT

Open Source Agenda Badge

Open Source Agenda Rating