-
-
Save k0kubun/48cc6777fa0e82dfcd74bf38f4a48222 to your computer and use it in GitHub Desktop.
Revised from https://github.com/ruby/ruby/pull/1921
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if RubyVM::MJIT.enabled? | |
RubyVM::MJIT.pause | |
end | |
require 'erb' | |
require 'shellwords' | |
methods = Integer(ARGV[0] || 1) | |
sleep_seconds = methods * 0.15 | |
loop_count = (250000000.0 / methods).to_i | |
src = ERB.new(<<-'erb', nil, '%').result(binding) | |
% methods.times do |i| | |
def call<%= i %>() nil end | |
call<%= i %>; call<%= i %> | |
% end | |
if RubyVM::MJIT.enabled? | |
RubyVM::MJIT.pause | |
end | |
i = 0 | |
before = Process.clock_gettime(Process::CLOCK_MONOTONIC) | |
while i < <%= loop_count %> | |
<%= methods.times.map { |i| "call#{i}; " }.join('') %> | |
i += 1 | |
end | |
after = Process.clock_gettime(Process::CLOCK_MONOTONIC) | |
puts((after - before).to_s) | |
erb | |
puts "\n```\n#{src}```\n\n" | |
results = [] | |
3.times do | |
if RubyVM::MJIT.enabled? | |
cmd = [RbConfig.ruby, '--disable-gems', '--jit-min-calls=2', '--jit-verbose=1', '--jit-max-cache=10000', '-e'] | |
else | |
cmd = [RbConfig.ruby, '--disable-gems', '-e'] | |
end | |
puts "+ #{cmd.shelljoin} ..." | |
result = IO.popen([*cmd, src], &:read) | |
results << result | |
puts "Result: #{result}\n" | |
end | |
puts "Avg: #{results.map(&:strip).map(&:to_f).inject(&:+) / results.size.to_f}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment