mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-15 08:50:45 -07:00
## Test code
```ruby
require 'benchmark/ips'
WhitespaceOrNothing = /\A\s*\z/
token = " " * 20
Benchmark.ips do |x|
x.report("WhitespaceOrNothing") {
token =~ WhitespaceOrNothing
}
x.report("strip & empty?") {
token.strip.empty?
}
x.compare!
end
```
## Result
```
Warming up --------------------------------------
WhitespaceOrNothing 266.391k i/100ms
strip & empty? 1.044M i/100ms
Calculating -------------------------------------
WhitespaceOrNothing 2.705M (± 0.4%) i/s - 13.586M in 5.023453s
strip & empty? 10.400M (± 1.1%) i/s - 52.182M in 5.017990s
Comparison:
strip & empty?: 10400286.2 i/s
WhitespaceOrNothing: 2704552.3 i/s - 3.85x (± 0.00) slower
```