Skip to content

Instantly share code, notes, and snippets.

@billywhizz
Last active November 18, 2024 00:11
Show Gist options
  • Save billywhizz/48020f258b447a42533b9eda2ffaa712 to your computer and use it in GitHub Desktop.
Save billywhizz/48020f258b447a42533b9eda2ffaa712 to your computer and use it in GitHub Desktop.
dumb-benchmark
GOAMD64=v2 go build foo.go
package main
import (
"time"
"fmt"
)
var array [10000]int
func bench() {
start := time.Now()
for i := 0; i < 10000; i++ {
for j := 0; j < 100000; j++ {
array[i] = array[i] + j
}
}
elapsed := time.Since(start)
fmt.Printf("%d\n", elapsed.Milliseconds())
}
func main() {
for i := 0; i < 10; i++ {
bench()
}
}
const array = new Uint32Array(10000);
array.fill(10000)
function test () {
const start = Date.now()
for (let i = 0; i < 10000; i++) {
for (let j = 0; j < 100000; j++) {
array[i] = array[i] + j;
}
}
const elapsed = Date.now() - start
console.log(elapsed)
}
for (let i = 0; i < 10; i++) {
test()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment