public
Created

Benchmark and results of Time.new.to_i versus java.lang.System.nanoTime called from JRuby.

  • Download Gist
a
1 2 3 4 5 6
Calculating -------------------------------------
Time.new.to_i 106740 i/100ms
System.nanoTime 187876 i/100ms
-------------------------------------------------
Time.new.to_i 5457230.7 (±7.3%) i/s - 27111960 in 5.000000s
System.nanoTime 17952011.5 (±9.2%) i/s - 88301720 in 4.976000s
bench_clock.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
require 'benchmark/ips'
 
java_import java.lang.System
 
Benchmark.ips do |bm|
bm.report('Time.new.to_i') do |n|
while n > 0
Time.new.to_i
n-=1
end
end
 
bm.report('System.nanoTime') do |n|
while n > 0
System.nano_time
n-=1
end
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.