Skip to content

Instantly share code, notes, and snippets.

@headius
Created March 15, 2013 06:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save headius/5167793 to your computer and use it in GitHub Desktop.
Save headius/5167793 to your computer and use it in GitHub Desktop.
Benchmark and results of Time.new.to_i versus java.lang.System.nanoTime called from JRuby.
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
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment