Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
require 'benchmark' # Original regular expressions original = Regexp.union( %r{\A(?:/\*.*?\*/)?\s*ROLLBACK}i, %r{\A(?:/\*.*?\*/)?\s*COMMIT}i, %r{\A(?:/\*.*?\*/)?\s*RELEASE\s+SAVEPOINT}i, ) # Combined regular expression combined = %r{\A(?:/\*.*?\*/)?\s*(ROLLBACK|COMMIT|RELEASE\s+SAVEPOINT)}i # Test string sql = "/* comment */ COMMIT" n = 1_000_000 Benchmark.bm do |x| x.report("original:") { n.times { original.match?(sql) } } x.report("combined:") { n.times { combined.match?(sql) } } end
- Loading branch information