Skip to content

Commit

Permalink
Merge pull request #44 from gmr458/improve-go-loops
Browse files Browse the repository at this point in the history
Improve Go loops
  • Loading branch information
bddicken authored Nov 29, 2024
2 parents d0ae86b + ebd7d31 commit 411e2b1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion compile.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
clang -O3 c/code.c -o c/code
go build -o go/code go/code.go
go build -ldflags "-s -w" -o go/code go/code.go
javac jvm/code.java
RUSTFLAGS="-Zlocation-detail=none" cargo +nightly build --manifest-path rust/Cargo.toml --release
kotlinc -include-runtime kotlin/code.kt -d kotlin/code.jar
Expand Down
10 changes: 5 additions & 5 deletions loops/go/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
func main() {
input, e := strconv.Atoi(os.Args[1]) // Get an input number from the command line
if e != nil { panic(e) }
u := int(input)
r := int(rand.Intn(10000)) // Get a random number 0 <= r < 10k
var a[10000]int // Array of 10k elements initialized to 0
for i := 0; i < 10000; i++ { // 10k outer loop iterations
for j := 0; j < 100000; j++ { // 100k inner loop iterations, per outer loop iteration
u := int32(input)
r := int32(rand.Intn(10000)) // Get a random number 0 <= r < 10k
var a[10000]int32 // Array of 10k elements initialized to 0
for i := int32(0); i < 10000; i++ { // 10k outer loop iterations
for j := int32(0); j < 100000; j++ { // 100k inner loop iterations, per outer loop iteration
a[i] = a[i] + j%u // Simple sum
}
a[i] += r // Add a random value to each element in array
Expand Down

0 comments on commit 411e2b1

Please sign in to comment.