Skip to content

Instantly share code, notes, and snippets.

@tjsingleton
Created July 1, 2010 08:25
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/459719 to your computer and use it in GitHub Desktop.
Save tjsingleton/459719 to your computer and use it in GitHub Desktop.
require "benchmark"
N = 1_000_000
Benchmark.bmbm do |sample|
HAYSTACK = "qqq100601.txt"
PATTERN = /\A([a-z]+)/
raise unless HAYSTACK[PATTERN, 1] == HAYSTACK.match(PATTERN)[0]
sample.report("[]") do
N.times do
HAYSTACK[PATTERN, 1]
end
end
sample.report("#match") do
N.times do
HAYSTACK.match(PATTERN)[0]
end
end
end
info: ruby-1.9.1-p378: ruby 1.9.1p378 (2010-01-10 revision 26273) [x86_64-darwin10.3.0]
Rehearsal ------------------------------------------
[] 0.810000 0.010000 0.820000 ( 0.814320)
#match 2.130000 0.000000 2.130000 ( 2.144490)
--------------------------------- total: 2.950000sec
user system total real
[] 0.810000 0.000000 0.810000 ( 0.811245)
#match 2.120000 0.010000 2.130000 ( 2.128847)
info: jruby-1.5.1: jruby 1.5.1 (ruby 1.8.7 patchlevel 249) (2010-06-06 f3a3480) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_20) [x86_64-java]
Rehearsal ------------------------------------------
[] 1.225000 0.000000 1.225000 ( 1.101000)
#match 0.861000 0.000000 0.861000 ( 0.861000)
--------------------------------- total: 2.086000sec
user system total real
[] 0.629000 0.000000 0.629000 ( 0.629000)
#match 0.753000 0.000000 0.753000 ( 0.753000)
info: macruby-0.6: MacRuby version 0.6 (ruby 1.9.0) [universal-darwin10.0, x86_64]
Rehearsal ------------------------------------------
[] 6.260000 0.160000 6.420000 ( 5.824495)
#match 9.910000 0.390000 10.300000 ( 8.720630)
-------------------------------- total: 16.720000sec
user system total real
[] 6.400000 0.180000 6.580000 ( 5.964845)
#match 10.050000 0.380000 10.430000 ( 8.869562)
info: rbx-1.0.0-20100514: rubinius 1.0.0 (1.8.7 release 2010-05-14 JI) [x86_64-apple-darwin10.3.0]
Rehearsal ------------------------------------------
[] 3.077733 0.000000 3.077733 ( 3.077725)
#match 2.075255 0.000000 2.075255 ( 2.075303)
--------------------------------- total: 5.152988sec
user system total real
[] 2.632010 0.000000 2.632010 ( 2.632035)
#match 1.933019 0.000000 1.933019 ( 1.933032)
info: ree-1.8.7-2010.01: ruby 1.8.7 (2009-12-24 patchlevel 248) [i686-darwin10.2.0], MBARI 0x6770, Ruby Enterprise Edition 2010.01
Rehearsal ------------------------------------------
[] 1.280000 0.000000 1.280000 ( 1.292379)
#match 2.130000 0.000000 2.130000 ( 2.134379)
--------------------------------- total: 3.410000sec
user system total real
[] 1.290000 0.000000 1.290000 ( 1.299103)
#match 2.130000 0.010000 2.140000 ( 2.138348)
info: ruby-1.8.6-p399: ruby 1.8.6 (2010-02-05 patchlevel 399) [i686-darwin10.2.0]
Rehearsal ------------------------------------------
[] 1.200000 0.000000 1.200000 ( 1.206999)
#match 1.940000 0.000000 1.940000 ( 1.946666)
--------------------------------- total: 3.140000sec
user system total real
[] 1.210000 0.000000 1.210000 ( 1.213804)
#match 1.980000 0.010000 1.990000 ( 1.981750)
info: ruby-1.8.7-p174: ruby 1.8.7 (2009-06-12 patchlevel 174) [x86_64-darwin10.4.0]
Rehearsal ------------------------------------------
[] 2.160000 0.000000 2.160000 ( 2.182711)
#match 3.330000 0.010000 3.340000 ( 3.340549)
--------------------------------- total: 5.500000sec
user system total real
[] 2.170000 0.000000 2.170000 ( 2.177104)
#match 3.330000 0.000000 3.330000 ( 3.341549)
info: ruby-1.8.7-p249: ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-darwin10.2.0]
Rehearsal ------------------------------------------
[] 1.200000 0.000000 1.200000 ( 1.207026)
#match 2.000000 0.000000 2.000000 ( 2.008801)
--------------------------------- total: 3.200000sec
user system total real
[] 1.190000 0.000000 1.190000 ( 1.200304)
#match 2.040000 0.010000 2.050000 ( 2.050523)
info: ruby-1.9.1-p378: ruby 1.9.1p378 (2010-01-10 revision 26273) [x86_64-darwin10.3.0]
Rehearsal ------------------------------------------
[] 0.810000 0.010000 0.820000 ( 0.821036)
#match 2.130000 0.000000 2.130000 ( 2.144366)
--------------------------------- total: 2.950000sec
user system total real
[] 0.800000 0.000000 0.800000 ( 0.806473)
#match 2.130000 0.010000 2.140000 ( 2.144384)
info: ruby-1.9.2-preview1: ruby 1.9.2dev (2009-07-18 trunk 24186) [i386-darwin10.3.0]
Rehearsal ------------------------------------------
[] 0.660000 0.000000 0.660000 ( 0.655423)
#match 1.970000 0.010000 1.980000 ( 1.984655)
--------------------------------- total: 2.640000sec
user system total real
[] 0.660000 0.000000 0.660000 ( 0.658629)
#match 1.960000 0.000000 1.960000 ( 1.962876)
info: ruby-1.9.2-preview3: ruby 1.9.2dev (2010-05-31 revision 28117) [x86_64-darwin10.4.0]
Rehearsal ------------------------------------------
[] 1.530000 0.000000 1.530000 ( 1.539949)
#match 4.050000 0.010000 4.060000 ( 4.063229)
--------------------------------- total: 5.590000sec
user system total real
[] 1.520000 0.000000 1.520000 ( 1.528749)
#match 4.060000 0.010000 4.070000 ( 4.075716)
Thread ID: 2148387240
Total: 0.000030
%self total self wait child calls name
86.67 0.00 0.00 0.00 0.00 1 Global#[No method]
13.33 0.00 0.00 0.00 0.00 1 String#[]
Thread ID: 2148387240
Total: 0.000036
%self total self wait child calls name
41.67 0.00 0.00 0.00 0.00 1 Global#[No method]
36.11 0.00 0.00 0.00 0.00 1 String#match
16.67 0.00 0.00 0.00 0.00 1 Regexp#match
5.56 0.00 0.00 0.00 0.00 1 MatchData#[]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment