Created
April 9, 2014 05:47
-
-
Save ijonas/10229518 to your computer and use it in GitHub Desktop.
Go / Node / Ruby Speed comparison
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math/rand" | |
"time" | |
) | |
func main() { | |
r := rand.New(rand.NewSource(99)) | |
total := 10000000 | |
fmt.Println("Prepping.") | |
start := time.Now() | |
docs := make([]map[string]float64, total) | |
for i := 0; i < total; i++ { | |
docs[i] = map[string]float64{ | |
"subtotal": r.Float64(), | |
"total": 0.0, | |
} | |
} | |
end := time.Now() | |
fmt.Printf("The calls took %v to run.\n", end.Sub(start)) | |
start = time.Now() | |
for i := 0; i < total; i++ { | |
docs[i]["total"] = docs[i]["subtotal"] * 1.2 | |
} | |
end = time.Now() | |
fmt.Printf("The calls took %v to run.\n", end.Sub(start)) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var total = 10000000 | |
console.log("Prepping.") | |
var start_ts = new Date().getTime() | |
var docs = [] | |
for (i=0; i<total; i++) { | |
docs.push({subtotal: Math.random(100), total: 0.0}) | |
} | |
var end_ts = new Date().getTime() | |
console.log("The prep took "+(end_ts-start_ts)+"ms to run.") | |
console.log("Ready.") | |
start_ts = new Date().getTime() | |
for (i=0; i<total; i++) { | |
docs[i]['total'] = docs[i]['subtotal'] * 1.2 | |
} | |
end_ts = new Date().getTime() | |
console.log("The calls took "+(end_ts-start_ts)+"ms to run.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "time" | |
total = 10000000 | |
puts("Prepping.") | |
start_ts = Time.now | |
docs = [] | |
total.times { | |
docs.push({subtotal: rand, total: 0.0}) | |
} | |
end_ts = Time.now | |
puts("The prep took #{(end_ts-start_ts)*1000}ms to run.") | |
puts("Ready.") | |
start_ts = Time.now | |
total.times { |i| | |
docs[i][:total] = docs[i][:subtotal] * 1.2 | |
} | |
end_ts = Time.now | |
puts("The calls took #{(end_ts-start_ts)*1000}ms to run.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment