Skip to content

Instantly share code, notes, and snippets.

@bradland
Created March 6, 2015 23:36
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/304a5f43cb581e890f1c to your computer and use it in GitHub Desktop.
Save bradland/304a5f43cb581e890f1c to your computer and use it in GitHub Desktop.
require 'benchmark'
alias e puts
N = "\n"
N_TIMES = 550_000 # Run it n times.
TEST_STRING = ('abc,def,ghi,jkl,'+N) * 80
Benchmark.bm(24) { |x|
x.report("Testing: split(',')") {
N_TIMES.times { TEST_STRING.split(',') }
}
x.report('Testing: split(/,/)') {
N_TIMES.times { TEST_STRING.split(/,/) }
}
}
@bradland
Copy link
Author

bradland commented Mar 6, 2015

                               user     system      total        real
Testing: split(',')       13.320000   0.030000  13.350000 ( 13.385362)
Testing: split(/,/)       40.990000   0.090000  41.080000 ( 41.165942)

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