Skip to content

Instantly share code, notes, and snippets.

@bradland
Last active December 10, 2015 12:59
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 bradland/4438185 to your computer and use it in GitHub Desktop.
Save bradland/4438185 to your computer and use it in GitHub Desktop.
Benchmark two types of log tags
#!/usr/bin/env ruby
require 'benchmark'
require 'date'
require 'securerandom'
Benchmark.bm(15) do|b|
ITERATE = 100_000
timestamp = Proc.new {Time.now.strftime('%Y-%m-%d %H:%M:%S.%L')}
b.report("proc time call") do
ITERATE.times { log_tags = [timestamp.call, SecureRandom.hex(16)] }
end
emptyproc = Proc.new {nil}
b.report("proc empty call") do
ITERATE.times { log_tags = [emptyproc.call, SecureRandom.hex(16)] }
end
b.report("uuid only") do
ITERATE.times { log_tags = [SecureRandom.hex(16)] }
end
end
@bradland
Copy link
Author

bradland commented Jan 2, 2013

Results:

                      user     system      total        real
proc call         1.430000   0.010000   1.440000 (  1.520804)
empty proc call   0.430000   0.000000   0.430000 (  0.440742)
uuid only         0.400000   0.000000   0.400000 (  0.405750)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment