Created
October 7, 2012 20:38
-
-
Save marete/3849522 to your computer and use it in GitHub Desktop.
Multithreaded RFC 868 (Time Server) Benchmark
This file contains 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 "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