Skip to content

Instantly share code, notes, and snippets.

@cpappen
Last active September 23, 2016 05:46
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 cpappen/1b0f04d339fb2ba8eea1be5b3ad787f2 to your computer and use it in GitHub Desktop.
Save cpappen/1b0f04d339fb2ba8eea1be5b3ad787f2 to your computer and use it in GitHub Desktop.
require 'benchmark'
n = 500_000
GIGA_SECOND = 10**9
time = Time.utc(2011, 4, 25, 0, 0, 0)
Benchmark.bm do |x|
x.report("with CONST") { for i in 1..n; time + GIGA_SECOND; end }
x.report("no CONST") { for i in 1..n; time + 10**9; end }
x.report("no CONST") { for i in 1..n; time+= 10**9; end }
x.report("with CONST") { for i in 1..n; time+= GIGA_SECOND; end }
end
# user system total real
# with CONST 0.130000 0.000000 0.130000 ( 0.127017)
# no CONST 0.180000 0.000000 0.180000 ( 0.179682)
# no CONST 0.140000 0.000000 0.140000 ( 0.149598)
# with CONST 0.140000 0.000000 0.140000 ( 0.132537)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment