Skip to content

Instantly share code, notes, and snippets.

@k0kubun k0kubun/loop.rb Secret
Created Jul 28, 2018

Embed
What would you like to do?
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 %>; call<%= i %>; call<%= i %>; call<%= i %>;
% end
if ENV['MJIT_ENABLE'] == 'true'
$stderr.puts "sleeping <%= sleep_seconds %>"
sleep <%= sleep_seconds %>
end
$stderr.puts "running"
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)
$stderr.puts "finish\n"
erb
puts "\n```\n#{src}```\n\n"
results = []
3.times do
if ENV['MJIT_ENABLE'] == 'true'
cmd = [RbConfig.ruby, '--disable-gems', '--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 "\n\nResult: #{result}\n\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
You can’t perform that action at this time.