Skip to content

Commit 165e18c

Browse files
committed
Updating hrtime and added time benchmarks.
1 parent c99174e commit 165e18c

14 files changed

+122
-6
lines changed

Makefile

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: hashing http queues json
1+
.PHONY: hashing http queues json time
22

33
projectpath = ${PWD}
44
glidepath = ${PWD}/vendor/github.com/Masterminds/glide
@@ -32,6 +32,17 @@ plot: results
3232
http:
3333
@go build -o build/http/evio http/evio.go
3434

35+
time: results
36+
@rm -rf ./results/time.*
37+
@go test ./time -benchmem -bench=. | tee ./results/time.log
38+
@Rscript plotting/gobench_single_nsop.r ./results/time.log ./results/time.png
39+
@Rscript ./plotting/hdr_histogram.r ./results/nanotime.histogram ./results/hrtime.histogram 1 results/time_p90.png
40+
@Rscript ./plotting/hdr_histogram.r ./results/nanotime.histogram ./results/hrtime.histogram 2 results/time_p99.png
41+
@Rscript ./plotting/hdr_histogram.r ./results/nanotime.histogram ./results/hrtime.histogram 3 results/time_p999.png
42+
@Rscript ./plotting/hdr_histogram.r ./results/nanotime.histogram ./results/hrtime.histogram 4 results/time_p9999.png
43+
@Rscript ./plotting/hdr_histogram.r ./results/nanotime.histogram ./results/hrtime.histogram 5 results/time_p99999.png
44+
@Rscript ./plotting/hdr_histogram.r ./results/nanotime.histogram ./results/hrtime.histogram 6 results/time_p999999.png
45+
3546
target:
3647
@go build
3748

glide.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

glide.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@ import:
4949
- package: github.com/pltr/onering
5050
- package: github.com/codahale/hdrhistogram
5151
- package: github.com/tylertreat/hdrhistogram-writer
52-
- package: github.com/loov/hrtime
5352
- package: github.com/mailru/easyjson
53+
- package: github.com/loov/hrtime

queues/one_to_one_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ func recordLatencyDistribution(name string, count int, startNanos []int64, endNa
238238

239239
func recordLatencyDistributionBenchmark(name string, bench *hrtime.BenchmarkTSC) {
240240
histogram := hdrhistogram.New(1, 1000000, 5)
241-
for _, lap := range bench.Laps {
241+
for _, lap := range bench.Laps() {
242242
histogram.RecordValue(int64(lap))
243243
}
244244
histwriter.WriteDistributionFile(histogram, nil, 1.0, "../results/"+name+".histogram")

results/time.png

266 KB
Loading

results/time_p90.png

192 KB
Loading

results/time_p99.png

191 KB
Loading

results/time_p999.png

187 KB
Loading

results/time_p9999.png

195 KB
Loading

results/time_p99999.png

188 KB
Loading

results/time_p999999.png

201 KB
Loading

time/README.md

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Introduction
2+
This directory includes queue implementation benchmarks for various different time stamp functions.
3+
4+
# Guarantees
5+
Different time functions have different tradeoffs.
6+
7+
### Staleness
8+
_TODO_
9+
10+
# Setup
11+
```
12+
Ubuntu Linux
13+
Intel(R) Xeon(R) CPU E5-2670 v2 @ 2.50GHz x 20 Cores (40 Hyperthreaded)
14+
L1 Cache: 320 kB
15+
L2 Cache: 2560 kB
16+
L3 Cache: 25600 kB
17+
Memory: 126 GB
18+
```
19+
20+
# Results
21+
[![results](../results/time.png)](https://github.com/kellabyte/go-benchmarks/raw/master/results/time.png)
22+
23+
### p90
24+
[![results](../results/time_p90.png)](https://github.com/kellabyte/go-benchmarks/raw/master/results/time_p90.png)
25+
### p99
26+
[![results](../results/time_p99.png)](https://github.com/kellabyte/go-benchmarks/raw/master/results/time_p99.png)
27+
### p999
28+
[![results](../results/time_p999.png)](https://github.com/kellabyte/go-benchmarks/raw/master/results/time_p999.png)
29+
### p9999
30+
[![results](../results/time_p9999.png)](https://github.com/kellabyte/go-benchmarks/raw/master/results/time_p9999.png)
31+
### p99999
32+
[![results](../results/time_p99999.png)](https://github.com/kellabyte/go-benchmarks/raw/master/results/time_p99999.png)
33+
### p999999
34+
[![results](../results/time_p99999.png)](https://github.com/kellabyte/go-benchmarks/raw/master/results/time_p99999.png)
35+
### p9999999
36+
[![results](../results/time_p999999.png)](https://github.com/kellabyte/go-benchmarks/raw/master/results/time_p999999.png)
37+
38+
```
39+
make queues
40+
41+
goos: darwin
42+
goarch: amd64
43+
pkg: github.com/kellabyte/go-benchmarks/time
44+
BenchmarkNanotime-8 100000000 18.9 ns/op 53.00 MB/s 0 B/op 0 allocs/op
45+
BenchmarkHrtime-8 100000000 20.6 ns/op 48.61 MB/s 0 B/op 0 allocs/op
46+
PASS
47+
ok github.com/kellabyte/go-benchmarks/time 11.624s
48+
```

time/nanos.s

Whitespace-only changes.

time/time_test.go

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//go:linkname nanotime runtime.nanotime
2+
package time
3+
4+
import (
5+
"testing"
6+
_ "unsafe"
7+
8+
"github.com/codahale/hdrhistogram"
9+
"github.com/loov/hrtime"
10+
"github.com/tylertreat/hdrhistogram-writer"
11+
)
12+
13+
func nanotime() int64
14+
15+
func BenchmarkNanotime(b *testing.B) {
16+
startNanos := make([]int64, b.N)
17+
endNanos := make([]int64, b.N)
18+
19+
b.ResetTimer()
20+
for i := 0; i < b.N; i++ {
21+
startNanos[i] = nanotime()
22+
endNanos[i] = nanotime()
23+
b.SetBytes(1)
24+
}
25+
26+
b.StopTimer()
27+
recordLatencyDistribution("nanotime", b.N, startNanos, endNanos)
28+
}
29+
30+
func BenchmarkHrtime(b *testing.B) {
31+
bench := hrtime.NewBenchmarkTSC(b.N)
32+
33+
b.ResetTimer()
34+
for bench.Next() {
35+
b.SetBytes(1)
36+
}
37+
38+
b.StopTimer()
39+
recordLatencyDistributionBenchmark("hrtime", bench)
40+
}
41+
42+
func recordLatencyDistribution(name string, count int, startNanos []int64, endNanos []int64) {
43+
histogram := hdrhistogram.New(1, 1000000, 5)
44+
for i := 0; i < count; i++ {
45+
diff := endNanos[i] - startNanos[i]
46+
histogram.RecordValue(diff)
47+
}
48+
histwriter.WriteDistributionFile(histogram, nil, 1.0, "../results/"+name+".histogram")
49+
}
50+
51+
func recordLatencyDistributionBenchmark(name string, bench *hrtime.BenchmarkTSC) {
52+
histogram := hdrhistogram.New(1, 1000000, 5)
53+
for _, lap := range bench.Laps() {
54+
histogram.RecordValue(int64(lap))
55+
}
56+
histwriter.WriteDistributionFile(histogram, nil, 1.0, "../results/"+name+".histogram")
57+
}

0 commit comments

Comments
 (0)