Last active
August 29, 2015 14:06
-
-
Save pzaich/e6de2fea0a7696aa658f to your computer and use it in GitHub Desktop.
Ruby regexes: benchmarking scan vs =~
This file contains hidden or 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
| r = /bobcat|sky track|framing|forklift|demolition|plumbing|drywall|concrete|RF & magnetic shielding|electrian|bossman|boss man|fencing|farm equipment|equipment|steel|a job|my job|ur job|working|building|adding onto|18 wheeler|nuclear|powerplant|equipment|work station|my work|motor|fitting|fittin|stainless steal|stainless steel|mechanic|pipe|pipe welding|7018|6010|boiler|tool box|toolbox|tool|grinder|underpaid|repair|Mike Rowe|Miller Electric Welding|manufacturing|metals|forestry & logging|commercial & industrial equipment|industrials|mining materials|tools equipment|trade school|clutch|cylinder|roof|day at the office|carpenter|driver|maintenanceweld|weldor|tig|mig|gmaw|line out|welder|welding|weldin|welding hood|weldin hood/i | |
| string = "my work station in nashville. over $20,000 of equipment sitting on that table" | |
| # =~ | |
| position_time = Benchmark.realtime do | |
| 1000.times do | |
| string =~ r | |
| end | |
| end | |
| # #scan | |
| scan_time = Benchmark.realtime do | |
| 1000.times do | |
| string.scan(r) | |
| end | |
| end | |
| puts 'scan time' | |
| puts scan_time | |
| puts 'Position =~ time' | |
| puts position_time | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment