Skip to content

Instantly share code, notes, and snippets.

@bradland
Created Mar 6, 2015
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@bradland 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