Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ Python 3.9.2

# TODO
- [x] Python codon
- [ ] Golang
- [ ] Rust nightly
- [x] Golang
- [ ] Rust nightly
34 changes: 34 additions & 0 deletions prime.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package main

import (
"fmt"
"math"
"time"
)

func isPrime(n int) bool {
if n <= 1 {
return false
}

end := int(math.Sqrt(float64(n)))
for i := 2; i <= end; i++ {
if n%i == 0 {
return false
}
}
return true
}

func main() {
start := float64(time.Now(). UnixMilli())
c := 0
for i := 0; i < 9000000; i++ {
if isPrime(i) {
c++
}
}
fmt.Println(c)
end := float64(time.Now().UnixMilli())
fmt.Printf("Execution time: %vms", end-start)
}
11 changes: 11 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,14 @@ sleep 5 # cpu cool down
python3 prime.py
echo ""



echo "*---------- go ----------*"
go version
go build ./prime.go

sleep 5 # cpu cool down

./prime.exe
rm ./prime.exe
echo ""