Last active
March 5, 2018 21:32
-
-
Save rsiddle/ec3f48d00c12619b5d25304365190f78 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
Benchmark.bm(7) do |x| | |
STR = 'l2yanS' | |
REGEX1 = /^(?=.*[a-z])(?=.*[A-Z])[a-zA-Z\d]{6}$/ | |
REGEX2 = /^(?=.*[a-z])(?=.*[A-Z])[0-9a-zA-Z]{6}$/ | |
x.report("Using backslash d:") { 1_000_000.times do | |
STR =~ REGEX1 | |
end } | |
x.report("Using 0-9:") { 1_000_000.times do | |
STR =~ REGEX2 | |
end } | |
end | |
# RESULTS | |
user system total real | |
Using backslash d: 0.450000 0.010000 0.460000 ( 0.453032) | |
Using 0-9: 0.470000 0.000000 0.470000 ( 0.475317) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment