rubybench_runner 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.travis.yml +7 -0
  4. data/CODE_OF_CONDUCT.md +74 -0
  5. data/Gemfile +6 -0
  6. data/Gemfile.lock +44 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +43 -0
  9. data/Rakefile +12 -0
  10. data/bin/console +15 -0
  11. data/bin/setup +8 -0
  12. data/exe/rubybench_runner +101 -0
  13. data/lib/rubybench_runner.rb +17 -0
  14. data/lib/rubybench_runner/base_runner.rb +233 -0
  15. data/lib/rubybench_runner/configurations.rb +68 -0
  16. data/lib/rubybench_runner/dependencies_checker.rb +39 -0
  17. data/lib/rubybench_runner/helpers_version +1 -0
  18. data/lib/rubybench_runner/rails/.bundle/config +4 -0
  19. data/lib/rubybench_runner/rails/benchmarks/assets/javascripts/application.js +3 -0
  20. data/lib/rubybench_runner/rails/benchmarks/assets/javascripts/one.js.erb +5 -0
  21. data/lib/rubybench_runner/rails/benchmarks/assets/javascripts/two.js +1 -0
  22. data/lib/rubybench_runner/rails/benchmarks/form_partials/first.html.erb +17 -0
  23. data/lib/rubybench_runner/rails/benchmarks/form_partials/heavy/_item.html.erb +12 -0
  24. data/lib/rubybench_runner/rails/benchmarks/form_partials/heavy/_second.html.erb +7 -0
  25. data/lib/rubybench_runner/rails/benchmarks/form_partials/heavy/_third.html.erb +8 -0
  26. data/lib/rubybench_runner/rails/benchmarks/form_partials/layouts/application.html.erb +29 -0
  27. data/lib/rubybench_runner/rails/benchmarks/partials/first.html.erb +19 -0
  28. data/lib/rubybench_runner/rails/benchmarks/partials/heavy/_item.html.erb +0 -0
  29. data/lib/rubybench_runner/rails/benchmarks/partials/heavy/_second.html.erb +7 -0
  30. data/lib/rubybench_runner/rails/benchmarks/partials/heavy/_third.html.erb +3 -0
  31. data/lib/rubybench_runner/rails/benchmarks/partials/layouts/application.html.erb +29 -0
  32. data/lib/rubybench_runner/rails/benchmarks/support/benchmark_rails.rb +14 -0
  33. data/lib/rubybench_runner/rails/benchmarks/support/echo_channel.rb +13 -0
  34. data/lib/rubybench_runner/rails/benchmarks/support/request_helper.rb +9 -0
  35. data/lib/rubybench_runner/rails/benchmarks/support/url_generation_base.rb +79 -0
  36. data/lib/rubybench_runner/rails/benchmarks/views/posts/_form.html.erb +29 -0
  37. data/lib/rubybench_runner/rails/benchmarks/views/posts/edit.html.erb +6 -0
  38. data/lib/rubybench_runner/rails/benchmarks/views/posts/index.html.erb +32 -0
  39. data/lib/rubybench_runner/rails/benchmarks/views/posts/index.json.jbuilder +4 -0
  40. data/lib/rubybench_runner/rails/benchmarks/views/posts/new.html.erb +5 -0
  41. data/lib/rubybench_runner/rails/benchmarks/views/posts/show.html.erb +19 -0
  42. data/lib/rubybench_runner/rails/benchmarks/views/posts/show.json.jbuilder +1 -0
  43. data/lib/rubybench_runner/rails_runner.rb +91 -0
  44. data/lib/rubybench_runner/support/benchmark_runner.rb +62 -0
  45. data/lib/rubybench_runner/support/helpers.rb +11 -0
  46. data/lib/rubybench_runner/support/setup/.bundle/config +4 -0
  47. data/lib/rubybench_runner/support/setup/Gemfile +11 -0
  48. data/lib/rubybench_runner/support/setup/bm_create_string_columns_setup.rb +16 -0
  49. data/lib/rubybench_runner/support/setup/bm_destroy_setup.rb +12 -0
  50. data/lib/rubybench_runner/support/setup/bm_discourse_setup.rb +164 -0
  51. data/lib/rubybench_runner/support/setup/bm_finders_setup.rb +37 -0
  52. data/lib/rubybench_runner/support/setup/bm_preload_setup.rb +41 -0
  53. data/lib/rubybench_runner/support/setup/bm_save_setup.rb +12 -0
  54. data/lib/rubybench_runner/support/setup/bm_scope_all_setup.rb +32 -0
  55. data/lib/rubybench_runner/support/setup/bm_scope_where_setup.rb +30 -0
  56. data/lib/rubybench_runner/support/setup/bm_validations_invalid_setup.rb +18 -0
  57. data/lib/rubybench_runner/support/setup/bm_validations_valid_setup.rb +30 -0
  58. data/lib/rubybench_runner/support/setup/bm_with_default_scope_setup.rb +29 -0
  59. data/lib/rubybench_runner/version.rb +5 -0
  60. data/rubybench_runner.gemspec +34 -0
  61. metadata +200 -0
@@ -0,0 +1,68 @@
1
+ module RubybenchRunner
2
+ class Configurations
3
+ CONFIG_PATH = File.join(Dir.home, ".rubybench_runner_config")
4
+ CONFIG_VERSION = 1
5
+ MYSQL_MAPPING = {
6
+ user: :username,
7
+ dbname: :database
8
+ }
9
+ DEFAULTS = {
10
+ postgres: {
11
+ user: "postgres",
12
+ dbname: "rubybench",
13
+ host: "localhost",
14
+ port: 5432,
15
+ password: nil
16
+ },
17
+ mysql2: {
18
+ user: "root",
19
+ dbname: "rubybench",
20
+ host: "localhost",
21
+ port: 3306,
22
+ password: nil
23
+ },
24
+ config_version: CONFIG_VERSION
25
+ }
26
+ def initialize(mysql_map: false)
27
+ @mysql_map = mysql_map
28
+ if !File.exists?(CONFIG_PATH)
29
+ File.write(CONFIG_PATH, YAML.dump(DEFAULTS))
30
+ end
31
+
32
+ if !config_changed?
33
+ puts "Error: You haven't configured how RubybenchRunner should connect to the database servers on your machine. Please update the #{CONFIG_PATH} file to have the right configurations."
34
+ exit 1
35
+ end
36
+ end
37
+
38
+ def [](key)
39
+ key = key.to_s
40
+ result = config
41
+ key.split(".").each do |k|
42
+ result = result[k] || result[k.to_sym]
43
+ end
44
+ result
45
+ end
46
+
47
+ def config
48
+ content = File.read(CONFIG_PATH)
49
+ if content != @content
50
+ @content = content
51
+ @parsed = YAML.load(@content)
52
+ if @mysql_map
53
+ MYSQL_MAPPING.each do |old, new|
54
+ next if !@parsed[:mysql2].key?(old)
55
+ val = @parsed[:mysql2][old]
56
+ @parsed[:mysql2][new] = val
57
+ @parsed[:mysql2].delete(old)
58
+ end
59
+ end
60
+ end
61
+ @parsed
62
+ end
63
+
64
+ def config_changed?
65
+ File.read(CONFIG_PATH) != YAML.dump(DEFAULTS)
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,39 @@
1
+ module RubybenchRunner
2
+ # TODO: ideally those should be fetched from rubybench.org API
3
+ CURRENT_PG_VERSION = "9.6"
4
+ CURRENT_MYSQL_VERSION = "5.6.24"
5
+
6
+ class MissingDependency < StandardError; end
7
+ class DependenciesChecker
8
+ def self.check
9
+ check_pg
10
+ check_mysql
11
+ end
12
+
13
+ def self.check_pg
14
+ output = `pg_config --version`.strip
15
+ output =~ /^PostgreSQL ([\d.]+)/
16
+ version = $1
17
+ if version != CURRENT_PG_VERSION
18
+ warn("PostgreSQL", version, CURRENT_PG_VERSION)
19
+ end
20
+ rescue Errno::ENOENT
21
+ raise MissingDependency.new("Postgres doesn't seem to be installed on your system. Please install it and run the benchmarks again")
22
+ end
23
+
24
+ def self.check_mysql
25
+ version = `mysql_config --version`.strip
26
+ if version != CURRENT_MYSQL_VERSION
27
+ warn("MySQL", version, CURRENT_MYSQL_VERSION)
28
+ end
29
+ rescue Errno::ENOENT
30
+ raise MissingDependency.new("MySQL doesn't seem to be installed on your system. Please install it and run the benchmarks again")
31
+ end
32
+
33
+ def self.warn(program, installed, recommended)
34
+ puts <<~ALERT
35
+ Warning: rubybench.org is currently running version #{recommended} of #{program}, you're running version #{installed}.
36
+ ALERT
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,4 @@
1
+ ---
2
+ BUNDLE_PATH: "vendor/bundle"
3
+ BUNDLE_DISABLE_SHARED_GEMS: "true"
4
+ BUNDLE_JOBS: "4"
@@ -0,0 +1,3 @@
1
+ //= require one.js
2
+ //= require_tree .
3
+ //= link two.js
@@ -0,0 +1,5 @@
1
+ $(function() {
2
+ <% 100.times do %>
3
+ $(body).append("testing");
4
+ <% end %>
5
+ })
@@ -0,0 +1,17 @@
1
+ <%= content_for(:title, "my title") %>
2
+ <%= content_for(:meta) { "embedded content" * 20 } %>
3
+ <% 3.times do |record| %>
4
+ <%= record %>
5
+ <p>
6
+ London is the capital city of England. It is the most populous city in the United Kingdom,
7
+ with a metropolitan area of over 13 million inhabitants.
8
+ </p>
9
+ <p>
10
+ Standing on the River Thames, London has been a major settlement for two millennia,
11
+ its history going back to its founding by the Romans, who named it Londinium.
12
+ </p>
13
+
14
+ <%= render partial: 'third', locals: { users: users } %>
15
+ <% end %>
16
+
17
+ <%= render collection: posts, partial: 'item', as: :post %>
@@ -0,0 +1,12 @@
1
+ <%= form_for post, url: '/posts' do |f|%>
2
+ <%= f.label :body %>
3
+ <%= f.text_field :body %>
4
+
5
+ <%= f.label :from %>
6
+ <%= f.text_field :from %>
7
+
8
+ <%= f.label :title %>
9
+ <%= f.text_field :title %>
10
+
11
+ <%= f.submit 'save' %>
12
+ <% end %>
@@ -0,0 +1,7 @@
1
+ <% posts.each do |post| %>
2
+ <h1><%= post.title %></h1>
3
+ <p><%= post.body %></p>
4
+ <small><%= post.from %></small>
5
+
6
+ <%= render partial: 'third', locals: { users: users } %>
7
+ <% end %>
@@ -0,0 +1,8 @@
1
+ <% users.each do |user| %>
2
+ <%= form_for user, url: '/users' do |f|%>
3
+ <%= f.label :email %>
4
+ <%= f.email_field :email %>
5
+
6
+ <%= f.submit 'save' %>
7
+ <% end %>
8
+ <% end %>
@@ -0,0 +1,29 @@
1
+ <html>
2
+ <head>
3
+ <title><%= yield(:title) %></title>
4
+ <meta><%= yield(:meta) %></meta>
5
+ </head>
6
+ <body>
7
+
8
+ <div id="header">
9
+ <h1>City Gallery</h1>
10
+ </div>
11
+
12
+ <div id="nav">
13
+ London<br>
14
+ Paris<br>
15
+ Tokyo<br>
16
+ </div>
17
+
18
+ <div id="section">
19
+ <h1>London</h1>
20
+ <%= yield %>
21
+ </div>
22
+
23
+ <div id="footer">
24
+ Copyright © W3Schools.com
25
+ </div>
26
+
27
+ </body>
28
+
29
+ </html>
@@ -0,0 +1,19 @@
1
+ <%= content_for(:title, "my title") %>
2
+ <%= content_for(:meta) { "embedded content" * 20 } %>
3
+ <% records.times do |record| %>
4
+ <%= record %>
5
+ <p>
6
+ London is the capital city of England. It is the most populous city in the United Kingdom,
7
+ with a metropolitan area of over 13 million inhabitants.
8
+ </p>
9
+ <p>
10
+ Standing on the River Thames, London has been a major settlement for two millennia,
11
+ its history going back to its founding by the Romans, who named it Londinium.
12
+ </p>
13
+
14
+ <%= render partial: 'second', locals: { posts: posts, users: users } %>
15
+ <% end %>
16
+
17
+ <%= render collections: posts, partial: 'item' %>
18
+
19
+ <%= debug @more_records %>
@@ -0,0 +1,7 @@
1
+ <% posts.each do |post| %>
2
+ <h1><%= post.title %></h1>
3
+ <p><%= post.body %></p>
4
+ <small><%= post.from %></small>
5
+
6
+ <%= render partial: 'third', locals: { users: users } %>
7
+ <% end %>
@@ -0,0 +1,3 @@
1
+ <% users.each do |user| %>
2
+ <%= user.email %>
3
+ <% end %>
@@ -0,0 +1,29 @@
1
+ <html>
2
+ <head>
3
+ <title><%= yield(:title) %></title>
4
+ <meta><%= yield(:meta) %></meta>
5
+ </head>
6
+ <body>
7
+
8
+ <div id="header">
9
+ <h1>City Gallery</h1>
10
+ </div>
11
+
12
+ <div id="nav">
13
+ London<br>
14
+ Paris<br>
15
+ Tokyo<br>
16
+ </div>
17
+
18
+ <div id="section">
19
+ <h1>London</h1>
20
+ <%= yield %>
21
+ </div>
22
+
23
+ <div id="footer">
24
+ Copyright © W3Schools.com
25
+ </div>
26
+
27
+ </body>
28
+
29
+ </html>
@@ -0,0 +1,14 @@
1
+ require 'rails'
2
+
3
+ require_relative '../../../support/benchmark_runner'
4
+ require_relative '../../../support/helpers'
5
+
6
+ module Benchmark
7
+ module Rails
8
+ def rails(label = nil, version: ::Rails.version.to_s, time:, disable_gc: true, warmup: 3, &block)
9
+ Benchmark::Runner.run(label, version: version, time: time, disable_gc: disable_gc, warmup: warmup, &block)
10
+ end
11
+ end
12
+
13
+ extend Benchmark::Rails
14
+ end
@@ -0,0 +1,13 @@
1
+ class EchoChannel < ApplicationCable::Channel
2
+ def subscribed
3
+ stream_from "echo_channel"
4
+ end
5
+
6
+ def unsubscribed
7
+ # Any cleanup needed when channel is unsubscribed
8
+ end
9
+
10
+ def ding(data)
11
+ transmit(dong: data['message'])
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ module RequestHelper
2
+ VALID_STATUS = [200, 302]
3
+
4
+ def self.perform(app, request)
5
+ status, _, body = app.call(request)
6
+ raise "Error: response status: #{status}" unless VALID_STATUS.include?(status)
7
+ body.close if body.respond_to?(:close)
8
+ end
9
+ end
@@ -0,0 +1,79 @@
1
+ require 'bundler/setup'
2
+
3
+ require 'rails'
4
+ require 'action_controller/railtie'
5
+
6
+ class NullLogger < Logger
7
+ def initialize(*args)
8
+ end
9
+
10
+ def add(*args, &block)
11
+ end
12
+ end
13
+
14
+ class BenchmarkApp < Rails::Application
15
+ routes.append do
16
+ namespace :editor do
17
+ resources :professionals
18
+ resource :message
19
+ end
20
+
21
+ scope path: '/prices' do
22
+ get 'info' => 'prices#info'
23
+ end
24
+
25
+ scope '/coupon' do
26
+ get 'some' => 'coupons#some'
27
+ end
28
+
29
+ root to: "home#index"
30
+
31
+ resources :topics do
32
+ resources :messages do
33
+ resources :likes
34
+ end
35
+ end
36
+
37
+ resources :professionals, only: [:index] do
38
+ collection do
39
+ match 'category/:specialization_id', to: 'professionals#by_category', as: :by_category, via: [:get, :post]
40
+ end
41
+ end
42
+
43
+ get "/listings/:any" => redirect("/properties/%{any}"), as: :listing_redirect
44
+
45
+ constraints id: /\d+(.*)/ do
46
+ get '/residential/*addressing_slug/:id',
47
+ to: 'residential_listings#show',
48
+ as: :residential
49
+ end
50
+ end
51
+
52
+ config.secret_token = "s"*30
53
+ config.secret_key_base = 'foo'
54
+ config.consider_all_requests_local = false
55
+
56
+ # simulate production
57
+ config.cache_classes = true
58
+ config.eager_load = true
59
+ config.action_controller.perform_caching = true
60
+
61
+ # otherwise deadlock occured
62
+ config.middleware.delete "Rack::Lock"
63
+
64
+ # to disable log files
65
+ config.logger = NullLogger.new
66
+ config.active_support.deprecation = :log
67
+ end
68
+
69
+ BenchmarkApp.initialize!
70
+
71
+ class Router
72
+ include BenchmarkApp.routes.url_helpers
73
+
74
+ def default_url_options
75
+ {
76
+ host: 'railsperf.io'
77
+ }
78
+ end
79
+ end
@@ -0,0 +1,29 @@
1
+ <%= form_for(@post) do |f| %>
2
+ <% if @post.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @post.errors.full_messages.each do |message| %>
8
+ <li><%= message %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="field">
15
+ <%= f.label :title %><br>
16
+ <%= f.text_field :title %>
17
+ </div>
18
+ <div class="field">
19
+ <%= f.label :body %><br>
20
+ <%= f.text_field :body %>
21
+ </div>
22
+ <div class="field">
23
+ <%= f.label :author %><br>
24
+ <%= f.text_field :author %>
25
+ </div>
26
+ <div class="actions">
27
+ <%= f.submit %>
28
+ </div>
29
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing Post</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Show', @post %> |
6
+ <%= link_to 'Back', posts_path %>
@@ -0,0 +1,32 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <h1>Listing Posts</h1>
4
+
5
+ <table>
6
+ <thead>
7
+ <tr>
8
+ <th>Title</th>
9
+ <th>Body</th>
10
+ <th>Author</th>
11
+ <th colspan="3"></th>
12
+ </tr>
13
+ </thead>
14
+
15
+ <tbody>
16
+ <%= posts_path %>
17
+ <% @posts.each do |post| %>
18
+ <tr>
19
+ <td><%= post.title %></td>
20
+ <td><%= post.body %></td>
21
+ <td><%= post.author %></td>
22
+ <td><%= link_to 'Show', post %></td>
23
+ <td><%= link_to 'Edit', edit_post_path(post) %></td>
24
+ <td><%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %></td>
25
+ </tr>
26
+ <% end %>
27
+ </tbody>
28
+ </table>
29
+
30
+ <br>
31
+
32
+ <%= link_to 'New Post', new_post_path %>