Skip to content

Commit

Permalink
Make -Iharness optional (#249)
Browse files Browse the repository at this point in the history
* Make -Iharness optional

* Add a comment about -Iharness

Co-authored-by: Maxime Chevalier-Boisvert <[email protected]>

* Rename harness/setup to harness/loader

---------

Co-authored-by: Maxime Chevalier-Boisvert <[email protected]>
  • Loading branch information
k0kubun and maximecb authored Sep 6, 2023
1 parent d9cdb22 commit cd063d5
Show file tree
Hide file tree
Showing 41 changed files with 44 additions and 41 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,9 @@ To run one or more specific benchmarks and record the data:
This is the easiest way to run a single benchmark.
It requires no setup at all and assumes nothing about the Ruby you are benchmarking.
It's also convenient for profiling, debugging, etc, especially since all benchmarked code runs in that process.
You can also use another harness or make your own by passing a different directory for `-I`.

```
ruby -Iharness benchmarks/some_benchmark.rb
ruby benchmarks/some_benchmark.rb
```

## Ruby options
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/30k_ifelse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240010,7 +240010,7 @@ def inc(x)

@x = 0

require 'harness'
require_relative '../harness/loader'

INTERNAL_ITRS = Integer(ENV.fetch("INTERNAL_ITRS", 600))

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/30k_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120007,7 +120007,7 @@ def inc()
@count += 1
end

require 'harness'
require_relative '../harness/loader'

INTERNAL_ITRS = Integer(ENV.fetch("INTERNAL_ITRS", 2000))

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/activerecord/benchmark.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "harness"
require_relative "../../harness/loader"

Dir.chdir __dir__
use_gemfile
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/binarytrees/benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def bottom_up_tree(depth)
max_depth = min_depth + 2 if min_depth + 2 > max_depth
stretch_depth = max_depth + 1

require 'harness'
require_relative '../../harness/loader'

run_benchmark(1) do
stretch_tree = bottom_up_tree(stretch_depth)
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/cfunc_itself.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'harness'
require_relative '../harness/loader'

run_benchmark(50) do
# 500K calls
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/chunky-png/benchmark.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "harness"
require_relative "../../harness/loader"

Dir.chdir __dir__
use_gemfile
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/erubi-rails/benchmark.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'harness'
require_relative '../../harness/loader'
Dir.chdir __dir__
use_gemfile

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/erubi/benchmark.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'harness'
require_relative '../../harness/loader'
Dir.chdir __dir__
use_gemfile

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/etanni/benchmark.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'harness'
require_relative '../../harness/loader'
Dir.chdir __dir__

# This is an Etanni translation of the Erb template in the Erubi
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/fannkuchredux/benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def fannkuch(n)
#n = (ARGV[0] || 1).to_i
n = 9 # Benchmarks Game uses n = 12, but it's too slow

require 'harness'
require_relative '../../harness/loader'

run_benchmark(5) do
5.times do
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/fib.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'harness'
require_relative '../harness/loader'

def fib(n)
if n < 2
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/fluentd/benchmark.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'harness'
require_relative '../../harness/loader'

Dir.chdir(__dir__)
use_gemfile
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/getivar.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'harness'
require_relative '../harness/loader'

class TheClass
def initialize
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/graphql-native/benchmark.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "harness"
require_relative "../../harness/loader"

Dir.chdir __dir__
use_gemfile
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/graphql/benchmark.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "harness"
require_relative "../../harness/loader"

Dir.chdir __dir__
use_gemfile
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/hexapdf/benchmark.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'harness'
require_relative '../../harness/loader'
Dir.chdir __dir__
use_gemfile

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/keyword_args.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'harness'
require_relative '../harness/loader'

def add(left:, right:)
left + right
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/lee/benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def lay(depth, solution)
end
end

require "harness"
require_relative "../../harness/loader"
Dir.chdir __dir__
use_gemfile

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/liquid-c/benchmark.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'harness'
require_relative '../../harness/loader'

Dir.chdir __dir__
use_gemfile
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/liquid-compile/benchmark.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'harness'
require_relative '../../harness/loader'

Dir.chdir __dir__
use_gemfile
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/liquid-render/benchmark.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'harness'
require_relative '../../harness/loader'

Dir.chdir __dir__
use_gemfile
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/lobsters/benchmark.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'harness'
require_relative '../../harness/loader'

ENV['RAILS_ENV'] ||= 'production'
ENV['DISABLE_DATABASE_ENVIRONMENT_CHECK'] = '1' # Benchmarks don't really have 'production', so trash it at will.
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/mail/benchmark.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "harness"
require_relative "../../harness/loader"

Dir.chdir __dir__
use_gemfile
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/nbody/benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def offset_momentum(bodies)
nbodies = BODIES.size
dt = 0.01

require 'harness'
require_relative '../../harness/loader'

run_benchmark(10) do
n.times do
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/optcarrot/benchmark.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'harness'
require_relative '../../harness/loader'
require_relative "lib/optcarrot"

rom_path = File.join(__dir__, "examples/Lan_Master.nes")
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/psych-load/benchmark.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'harness'
require_relative '../../harness/loader'

Dir.chdir __dir__
use_gemfile
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/rack/benchmark.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require "harness"
require_relative "../../harness/loader"

Dir.chdir(__dir__)
use_gemfile
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/railsbench/benchmark.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'harness'
require_relative '../../harness/loader'

ENV['RAILS_ENV'] ||= 'production'

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/respond_to.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Microbenchmark to test the performance of respond_to?
# This is one of the top most called methods in rack/railsbench

require 'harness'
require_relative '../harness/loader'

class A
def foo
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/ruby-json/benchmark.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "harness"
require_relative "../../harness/loader"

require "json"
require "strscan"
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/ruby-lsp/benchmark.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require "harness"
require_relative "../../harness/loader"

Dir.chdir(__dir__)
use_gemfile
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/rubykon/benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# https://github.com/benchmark-driver/sky2-bench/blob/master/benchmark/rubykon-benchmark.rb,
# part of benchmark-driver's default benchmarking suite, by Takashi Kokubun.

require 'harness'
require_relative '../../harness/loader'

require_relative 'lib/rubykon'

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/sequel/benchmark.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "harness"
require_relative "../../harness/loader"
require "securerandom" # Provides `Random::Formatter` in Ruby 2.6+

Dir.chdir __dir__
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/setivar.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'harness'
require_relative '../harness/loader'

class TheClass
def initialize
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/setivar_object.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'harness'
require_relative '../harness/loader'

class TheClass
def initialize
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/setivar_young.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'harness'
require_relative '../harness/loader'

class TheClass
def initialize
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/str_concat.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
require 'harness'
require_relative '../harness/loader'

NUM_ITERS = 10 * 1024
TEST_STR = 'sssssséé'
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/throw.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'harness'
require_relative '../harness/loader'

def foo
yield
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/tinygql/benchmark.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "harness"
require_relative "../../harness/loader"

Dir.chdir __dir__
use_gemfile
Expand Down
4 changes: 4 additions & 0 deletions harness/loader.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Use harness/harness.rb by default. You can change it with -I option.
# i.e. ruby -Iharness benchmarks/railsbench/benchmark.rb
$LOAD_PATH << File.expand_path(__dir__)
require "harness"

0 comments on commit cd063d5

Please sign in to comment.