lauantai 20. huhtikuuta 2019
How the Boeing 737 Max Disaster Looks to a Software Developer
How the Boeing 737 Max Disaster Looks to a Software Developer: Design shortcuts meant to make a new plane seem like an old, familiar one are to blame
lauantai 6. huhtikuuta 2019
One timewasting sieve more: The Go version
Studied Go (or Golang) for work, and of course wanted to gauge its performance. Here is a port of the sieve benchmark.
// Sieve benchmark in Go, based on the Java code at
// http://rsb.info.nih.gov/nih-image/java/benchmarks/Sieve.java
package main
import (
"time"
"math"
"strconv"
)
func main () {
const SIZE = 8190
// For "similarness" with other versions, allocate dynamically
var flags []bool = make([]bool, SIZE+1)
var i, prime, k, count int
var iterations int = 0
var seconds float64
var score int = 0
var startTime time.Time
var elapsedTime time.Duration = 0
var tenSeconds time.Duration
tenSeconds, _ = time.ParseDuration("10s")
startTime = time.Now();
for elapsedTime < tenSeconds {
count=0;
for i=0; i<=SIZE; i++ {
flags[i]=true;
}
for i=0; i<=SIZE; i++ {
if flags[i] {
prime=i+i+3
for k=i+prime; k<=SIZE; k+=prime {
flags[k]=false
}
count++
}
}
iterations++
elapsedTime = time.Now().Sub(startTime)
}
seconds = elapsedTime.Seconds()
score = int(math.Round(float64(iterations) / seconds))
println(strconv.Itoa(iterations) + " iterations in " +
strconv.FormatFloat(seconds, 'g', -1, 64) + " seconds")
if count != 1899 {
println("Error: count <> 1899")
} else {
println("Sieve score = " + strconv.Itoa(score))
}
}
// Sieve benchmark in Go, based on the Java code at
// http://rsb.info.nih.gov/nih-image/java/benchmarks/Sieve.java
package main
import (
"time"
"math"
"strconv"
)
func main () {
const SIZE = 8190
// For "similarness" with other versions, allocate dynamically
var flags []bool = make([]bool, SIZE+1)
var i, prime, k, count int
var iterations int = 0
var seconds float64
var score int = 0
var startTime time.Time
var elapsedTime time.Duration = 0
var tenSeconds time.Duration
tenSeconds, _ = time.ParseDuration("10s")
startTime = time.Now();
for elapsedTime < tenSeconds {
count=0;
for i=0; i<=SIZE; i++ {
flags[i]=true;
}
for i=0; i<=SIZE; i++ {
if flags[i] {
prime=i+i+3
for k=i+prime; k<=SIZE; k+=prime {
flags[k]=false
}
count++
}
}
iterations++
elapsedTime = time.Now().Sub(startTime)
}
seconds = elapsedTime.Seconds()
score = int(math.Round(float64(iterations) / seconds))
println(strconv.Itoa(iterations) + " iterations in " +
strconv.FormatFloat(seconds, 'g', -1, 64) + " seconds")
if count != 1899 {
println("Error: count <> 1899")
} else {
println("Sieve score = " + strconv.Itoa(score))
}
}
Tilaa:
Blogitekstit (Atom)