Last active
November 18, 2024 00:11
-
-
Save billywhizz/48020f258b447a42533b9eda2ffaa712 to your computer and use it in GitHub Desktop.
dumb-benchmark
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
GOAMD64=v2 go build foo.go |
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 ( | |
"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() | |
} | |
} |
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
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