Skip to content

Instantly share code, notes, and snippets.

Created November 16, 2008 06:11
Show Gist options
  • Save anonymous/25410 to your computer and use it in GitHub Desktop.
Save anonymous/25410 to your computer and use it in GitHub Desktop.
require 'benchmark'
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib' )))
require 'randomaze'
COUNT = 1000
template_str = 'abc[a-z]{3}foobar[0-9あいう]{5}__hoge'
parse_result = Randomaze::String::TemplateParser.parse(template_str)
Benchmark.bm do |x|
x.report 'from_array' do
COUNT.times do
Randomaze::String.from_template(parse_result)
end
end
x.report 'with format' do
COUNT.times do
Randomaze::String.format(template_str)
end
end
end
# On my environment( MacBook1.1 Intel Core Duo 1.83 GHz, 2GB), result is like that.
#
# ----------------------------------------------------------
# result after 92ed088b6 ( before 0.0.4 )
# user system total real
# from_array 0.150000 0.000000 0.150000 ( 0.170900)
# with format 0.370000 0.010000 0.380000 ( 0.421892)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment