Closed casperisfine closed 7 years ago
Another note, the more dots the name contains, the slower split('.').last
, whereas rpartition
is less impacted.
Same benchmark using: DOMAIN = 'foo.bar.plop.accident-prevention.aero'
Warming up --------------------------------------
string.rindex + string.slice
115.205k i/100ms
string.rpartition 100.624k i/100ms
split.last 64.506k i/100ms
string.scan 7.866k i/100ms
regexp.match 14.208k i/100ms
string.slice 16.540k i/100ms
Calculating -------------------------------------
string.rindex + string.slice
1.859M (± 3.1%) i/s - 9.332M in 5.024148s
string.rpartition 1.515M (± 3.1%) i/s - 7.647M in 5.054116s
split.last 871.871k (± 2.5%) i/s - 4.386M in 5.034232s
string.scan 80.564k (± 4.1%) i/s - 409.032k in 5.086318s
regexp.match 151.134k (± 1.5%) i/s - 767.232k in 5.077662s
string.slice 174.542k (± 2.7%) i/s - 876.620k in 5.026302s
Following https://github.com/weppos/publicsuffix-ruby/pull/128 I looked into
PublicSuffix::Domain.name_to_labels
's performance.The thing is, it's almost always used to get the TLD, so I benchmark several implementations:
So using
string.rpartition('.')[2]
is 30% faster thanstring.split('.').last
.It probably won't make a huge difference, but it might shave a few ms off the
reindex!
.@weppos thoughts ?