Skip to content

Instantly share code, notes, and snippets.

@tjsingleton
Created October 16, 2012 15:08
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 tjsingleton/57a90d921b58fcba7883 to your computer and use it in GitHub Desktop.
Save tjsingleton/57a90d921b58fcba7883 to your computer and use it in GitHub Desktop.
statsd parser
tests = [
'test:123|g',
'test:1232|g',
'timer:1235|ms',
'invalid',
'countera:1234|c',
'counterb:12234|c|@1.0',
'counterc:1234|c|@1',
'counterd:12234|c|@1.01',
'countere:-12|c|@1.0',
'gauge:1|g',
'gauge.complex:1123|g'
]
joined_tests = tests.join("\n")
require "pp"
require "benchmark"
N = 10_000
parser = StatsD::Parser.new
pp parser.run(joined_tests)
puts "Parser: #{parser.class}, N: #{N}"
Benchmark.bmbm do |x|
x.report("Single Line") { N.times { tests.each {|n| parser.run(n) } } }
x.report("Multiple Lines") { N.times { parser.run(joined_tests) } }
end
Ruby, manual string mangling (Node's algorithm)
Parser: NodeParser, N: 10000
Rehearsal --------------------------------------------------
Single Line 0.960000 0.000000 0.960000 ( 1.209171)
Multiple Lines 0.880000 0.010000 0.890000 ( 1.035960)
----------------------------------------- total: 1.850000sec
user system total real
Single Line 1.000000 0.000000 1.000000 ( 1.740574)
Multiple Lines 0.880000 0.010000 0.890000 ( 0.901065)
Ragel -> Ruby
Parser: StatsD::Parser, N: 10000
Rehearsal --------------------------------------------------
Single Line 5.510000 0.020000 5.530000 ( 5.975759)
Multiple Lines 5.190000 0.010000 5.200000 ( 5.531701)
---------------------------------------- total: 10.730000sec
user system total real
Single Line 5.540000 0.010000 5.550000 ( 5.682052)
Multiple Lines 5.110000 0.020000 5.130000 ( 5.281538)
Ragel -> C Ruby Ext
Parser: StatsD::Parser, N: 10000
Rehearsal --------------------------------------------------
Single Line 0.100000 0.000000 0.100000 ( 0.100121)
Multiple Lines 0.060000 0.000000 0.060000 ( 0.054484)
----------------------------------------- total: 0.160000sec
user system total real
Single Line 0.090000 0.000000 0.090000 ( 0.096089)
Multiple Lines 0.060000 0.000000 0.060000 ( 0.054760)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment