Created
August 3, 2012 19:18
-
-
Save fetep/3250576 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'benchmark' | |
N=1000 # number of parse iterations | |
T=10000 # number of timer update samples | |
# build some sample timer update strings w/#{T} values | |
samples = [] | |
T.times { samples << ((Kernel.rand(1000) + 100.0) / 100.0) } | |
v1_sample_update = "app.foo.response_time|#{samples.join(',')}|t" | |
v2_sample_update = "t|app.foo.response_time|#{samples.join(',')}" | |
# V1 parsing (split, no to_i) | |
t = Benchmark.realtime do | |
N.times do | |
metric, samples, update_type = v1_sample_update.split("|") | |
samples = samples.split(",") | |
end | |
end | |
puts "v1 split parsing (without to_i): #{t*1000/N}ms per message" | |
# V1 parsing (split, to_f) | |
t = Benchmark.realtime do | |
N.times do | |
metric, samples, update_type = v1_sample_update.split("|") | |
samples = samples.split(",").collect { |s| s.to_i } | |
end | |
end | |
puts "v1 split parsing (with to_i): #{t*1000/N}ms per message" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ruby-1.9.2-p320 | |
v1 split parsing (without to_i): 1.7741000652313232ms per message | |
v1 split parsing (with to_i): 3.394620180130005ms per message |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment