agworld/sass — comment on commit 3db1961723fed015ef7e430a689602b60bcfc02d
File: lib/sass/scss/parser.rb line 953
By jasonhutchens:

That needs to be `foo.slice!(-last_group.length..-1)` to remove the matched group from the end of the string. I tried profiling the two approaches as follows, assuming that `res` might be rather long:

```ruby
#!/usr/bin/env ruby

require 'rubygems'
require 'ruby-prof'

STRING = "wooloomooloo" * 1000
GROUP = "loo"
LOOP = 1_000_000

last_group = GROUP

result = RubyProf.profile do
LOOP.times do
res = STRING
res.chomp!(last_group)
end
end
printer = RubyProf::FlatPrinter.new(result)
printer.print(STDOUT)

result = RubyProf.profile do
LOOP.times do
res = STRING
res.slice!(-3 .. -1)
end
end
printer = RubyProf::FlatPrinter.new(result)
printer.print(STDOUT)
```

In ree / 1.8.7 the output is:

```
Thread ID: 2230733880
Total: 3.647328

%self total self wait child calls name
75.35 3.65 2.75 0.00 0.90 1 Integer#times (ruby_runtime:0}
24.65 0.90 0.90 0.00 0.00 1000000 String#chomp! (ruby_runtime:0}
0.00 3.65 0.00 0.00 3.65 1 Global#[No method] (./slice.rb:13}

Thread ID: 2230733880
Total: 4.155965

%self total self wait child calls name
71.19 4.16 2.96 0.00 1.20 1 Integer#times (ruby_runtime:0}
28.81 1.20 1.20 0.00 0.00 1000000 String#slice! (ruby_runtime:0}
0.00 4.16 0.00 0.00 4.16 1 Global#[No method] (./slice.rb:22}
```

And in 1.9.2 the output is:

```
Thread ID: 70253547835080
Total: 3.701557

%self total self wait child calls name
72.18 3.70 2.67 0.00 1.03 1 Integer#times
27.82 1.03 1.03 0.00 0.00 1000000 String#chomp!
0.00 3.70 0.00 0.00 3.70 1 Global#[No method]

Thread ID: 70253547835080
Total: 3.842734

%self total self wait child calls name
69.79 3.84 2.68 0.00 1.16 1 Integer#times
30.21 1.16 1.16 0.00 0.00 1000000 String#slice!
0.00 3.84 0.00 0.00 3.84 1 Global#[No method]
```

So it seems that `chomp!` may be preferable for performance regardless?