maccman/sourcemap — pull request #12 by elia (2014-10-01 22:08:21+00:00)
Title: Prefer Array#join over String#<<

Reasons:

1. @opal doesn't have mutable strings
2. Array#join is faster (see below)

```
Calculating -------------------------------------
mutable 30801 i/100ms
join 39253 i/100ms
-------------------------------------------------
mutable 374769.7 (±2.4%) i/s - 3757722 in 10.032571s
join 501529.1 (±5.2%) i/s - 5024384 in 10.051695s

Comparison:
join: 501529.1 i/s
mutable: 374769.7 i/s - 1.34x slower
```

[test source:](https://gist.github.com/elia/d642e98934ab87e109cc)

```ruby
require 'benchmark/ips'

Benchmark.ips do |x|
# These parameters can also be configured this way
x.time = 10
x.warmup = 2

# Typical mode, runs the block as many times as it can
x.report("mutable") do
s1 = "sfkjahlkdfhajskfdhlajsdhflasjkhfdlajkshflajshdlfkjashldfkjahslkfjhalsdfasd"
s2 = "sfkjahlkdfhajskfdhlajsdhflasjkhfdlajkshflajshdlfkjashldfkjahslkfjhalsdfasd"
s3 = "sfkjahlkdfhajskfdhlajsdhflasjkhfdlajkshflajshdlfkjashldfkjahslkfjhalsdfasd"
s4 = "sfkjahlkdfhajskfdhlajsdhflasjkhfdlajkshflajshdlfkjashldfkjahslkfjhalsdfasd"
s5 = "sfkjahlkdfhajskfdhlajsdhflasjkhfdlajkshflajshdlfkjashldfkjahslkfjhalsdfasd"
s6 = "sfkjahlkdfhajskfdhlajsdhflasjkhfdlajkshflajshdlfkjashldfkjahslkfjhalsdfasd"
s7 = "sfkjahlkdfhajskfdhlajsdhflasjkhfdlajkshflajshdlfkjashldfkjahslkfjhalsdfasd"
s8 = "sfkjahlkdfhajskfdhlajsdhflasjkhfdlajkshflajshdlfkjashldfkjahslkfjhalsdfasd"
s9 = "sfkjahlkdfhajskfdhlajsdhflasjkhfdlajkshflajshdlfkjashldfkjahslkfjhalsdfasd"
s10 = "sfkjahlkdfhajskfdhlajsdhflasjkhfdlajkshflajshdlfkjashldfkjahslkfjhalsdfasd"
s11 = "sfkjahlkdfhajskfdhlajsdhflasjkhfdlajkshflajshdlfkjashldfkjahslkfjhalsdfasd"
s12 = "sfkjahlkdfhajskfdhlajsdhflasjkhfdlajkshflajshdlfkjashldfkjahslkfjhalsdfasd"
s1 << s2 << s3 << s4 << s5 << s6 << s7 << s8 << s9 << s10 << s11 << s12
end

# To reduce overhead, the number of iterations is passed in
# and the block must run the code the specific number of times.
# Used for when the workload is very small and any overhead
# introduces incorrectable errors.
x.report("join") do
s1 = "sfkjahlkdfhajskfdhlajsdhflasjkhfdlajkshflajshdlfkjashldfkjahslkfjhalsdfasd"
s2 = "sfkjahlkdfhajskfdhlajsdhflasjkhfdlajkshflajshdlfkjashldfkjahslkfjhalsdfasd"
s3 = "sfkjahlkdfhajskfdhlajsdhflasjkhfdlajkshflajshdlfkjashldfkjahslkfjhalsdfasd"
s4 = "sfkjahlkdfhajskfdhlajsdhflasjkhfdlajkshflajshdlfkjashldfkjahslkfjhalsdfasd"
s5 = "sfkjahlkdfhajskfdhlajsdhflasjkhfdlajkshflajshdlfkjashldfkjahslkfjhalsdfasd"
s6 = "sfkjahlkdfhajskfdhlajsdhflasjkhfdlajkshflajshdlfkjashldfkjahslkfjhalsdfasd"
s7 = "sfkjahlkdfhajskfdhlajsdhflasjkhfdlajkshflajshdlfkjashldfkjahslkfjhalsdfasd"
s8 = "sfkjahlkdfhajskfdhlajsdhflasjkhfdlajkshflajshdlfkjashldfkjahslkfjhalsdfasd"
s9 = "sfkjahlkdfhajskfdhlajsdhflasjkhfdlajkshflajshdlfkjashldfkjahslkfjhalsdfasd"
s10 = "sfkjahlkdfhajskfdhlajsdhflasjkhfdlajkshflajshdlfkjashldfkjahslkfjhalsdfasd"
s11 = "sfkjahlkdfhajskfdhlajsdhflasjkhfdlajkshflajshdlfkjashldfkjahslkfjhalsdfasd"
s12 = "sfkjahlkdfhajskfdhlajsdhflasjkhfdlajkshflajshdlfkjashldfkjahslkfjhalsdfasd"
[s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12].join
end

# Compare the iterations per second of the various reports!
x.compare!
end
```