Skip to content

Commit

Permalink
add benchmarks for timing functions
Browse files Browse the repository at this point in the history
  • Loading branch information
egonelbre committed Apr 30, 2018
1 parent d7e70d0 commit f0e5399
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions now_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package hrtime_test

import (
"testing"
"time"

"github.com/loov/hrtime"
)
Expand Down Expand Up @@ -39,3 +40,15 @@ func TestNowPrecision(t *testing.T) {

//go:noinline
func empty() {}

func BenchmarkTimeNow(b *testing.B) {
for i := 0; i < b.N; i++ {
time.Now()
}
}

func BenchmarkNow(b *testing.B) {
for i := 0; i < b.N; i++ {
hrtime.Now()
}
}
10 changes: 10 additions & 0 deletions tsc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,13 @@ func TestCountPrecision(t *testing.T) {
t.Errorf("fast: loop time took %v", loopTime)
}
}

func BenchmarkTSC(b *testing.B) {
if !hrtime.TSCSupported() {
b.Skip("Cycle counting not supported")
}

for i := 0; i < b.N; i++ {
hrtime.TSC()
}
}

0 comments on commit f0e5399

Please sign in to comment.