From: "trans (Thomas Sawyer)" Date: 2013-08-27T08:19:46+09:00 Subject: [ruby-core:56816] [ruby-trunk - Feature #8820] Speed up Array#index Issue #8820 has been updated by trans (Thomas Sawyer). Yes, sorry. I meant to use a random index with each iteration, not `i`. But per the suggestion, I think `i % 100` would be better. I changed and reran the benchmarks. But even so the comparison still comes out about the same ratio: Ruby: 35.66597 Go: 1.39305 ---------------------------------------- Feature #8820: Speed up Array#index https://bugs.ruby-lang.org/issues/8820#change-41357 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/