Skip to content

Instantly share code, notes, and snippets.

@marete
Created October 7, 2012 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marete/3849522 to your computer and use it in GitHub Desktop.
Save marete/3849522 to your computer and use it in GitHub Desktop.
Multithreaded RFC 868 (Time Server) Benchmark
package main
import "github.com/marete/rfc868"
import "time"
import "fmt"
import "runtime"
import "log"
const iterations = 1000000
const con = 10 // concurrency
type report struct {
passed int
failed int
}
func init() {
if iterations % con != 0 {
log.Fatalln("con =", con, " does not divide it =", iterations,
"evenly")
}
}
func main() {
runtime.GOMAXPROCS(con + 2)
ch := make(chan report, con)
for i := 0; i < con; i++ {
go func() {
c, err := rfc868.NewClient("127.0.0.1:1024")
if err != nil {
panic(err)
}
passed := 0
failed := 0
for j := 0; j < iterations/con; j++ {
_, err := c.RequestTime()
if err != nil {
failed++
} else {
passed++
}
}
ch <- report{passed, failed}
}()
}
start := time.Now()
passed := 0
failed := 0
for i := 0; i < con; i++ {
r := <- ch
passed += r.passed
failed += r.failed
}
nano := float32(time.Since(start))
secs := nano/float32(time.Second)
fmt.Println(iterations/secs, "r/s,", "passed:", passed,
"failed:", failed)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment