From: "trans (Thomas Sawyer)" Date: 2013-08-27T02:31:38+09:00 Subject: [ruby-core:56809] [ruby-trunk - Feature #8820][Open] Speed up Array#index Issue #8820 has been reported by trans (Thomas Sawyer). ---------------------------------------- Feature #8820: Speed up Array#index https://bugs.ruby-lang.org/issues/8820 Author: trans (Thomas Sawyer) Status: Open Priority: Normal Assignee: Category: core Target version: next minor I did a quick comparison: In Ruby def main n = 10000000 # ten million a = randPerm(100) t0 = Time.now n.times do |i| a.index(i) end puts "%.5f" % [Time.now - t0] end def randPerm(n) (0...n).sort_by{rand} end main() In Go package main import ( "fmt" "time" "math/rand" ) func main() { n := 10000000 // ten million a := rand.Perm(100) t0 := time.Now() for i := 0; i < n; i++ { index(a, i) } fmt.Printf("%.5f\n", time.Now().Sub(t0).Seconds()) } func index(slice []int, value int) int { for i, v := range slice { if (v == value) { return i } } return -1 } The result Ruby: 71.08961 secs Go: 2.61975 secs That's pretty huge difference (and worse I was told my Go index function was "crazily inefficient" too, though personally I don't see how it can be any better). So, I thought I'd mention it. Maybe it would be possible to speed up. -- http://bugs.ruby-lang.org/