Skip to content

Commit

Permalink
Add benchmark test and results
Browse files Browse the repository at this point in the history
  • Loading branch information
aswinkarthik committed Apr 23, 2018
1 parent 4973ec1 commit facb093
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,7 @@ $ go test -v ./...
## Credits

- Uses 64 bit [xxHash](https://cyan4973.github.io/xxHash/) algorithm, an extremely fast non-cryptographic hash algorithm, for creating the hash. Implementations from [cespare](https://github.com/cespare/xxhash)

## [Benchmarks](/benchmark)

- It can compare 10 Million CSV records in under 2 minutes.
19 changes: 19 additions & 0 deletions benchmark/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Benchmark Results

Benchmark test can be found [here](https://github.com/aswinkarthik93/csvdiff/blob/master/pkg/digest/digest_benchmark_test.go).

```bash
$ cd ./pkg/digest
$ go test -bench=. -v -benchmem -benchtime=5s -cover
```

| | | | | |
| ---------------------------- | ---------- | ----------------------- | -------------------- | ------------------- |
| BenchmarkCreate1-8 | 2000000 | 5967 ns/op | 5474 B/op | 21 allocs/op |
| BenchmarkCreate10-8 | 500000 | 16251 ns/op | 10889 B/op | 94 allocs/op |
| BenchmarkCreate100-8 | 100000 | 114219 ns/op | 67139 B/op | 829 allocs/op |
| BenchmarkCreate1000-8 | 10000 | 1042723 ns/op | 674239 B/op | 8078 allocs/op |
| BenchmarkCreate10000-8 | 1000 | 10386850 ns/op | 6533806 B/op | 80306 allocs/op |
| BenchmarkCreate100000-8 | 100 | 108740944 ns/op | 64206718 B/op | 804208 allocs/op |
| BenchmarkCreate1000000-8 | 5 | 1161730558 ns/op | 672048142 B/op | 8039026 allocs/op |
| BenchmarkCreate10000000-8 | 1 | 12721982424 ns/op | 6549111872 B/op| 80308455 allocs/op |
61 changes: 61 additions & 0 deletions pkg/digest/digest_benchmark_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package digest

import (
"fmt"
"io"
"testing"
)

const SomeText = "something-name-%d,346345ty,fdhfdh,5436456,gfgjfgj,45234545,nfhgjfgj,45745745,djhgfjfgj"

func BenchmarkCreate1(b *testing.B) { benchmarkCreate(1, b) }
func BenchmarkCreate10(b *testing.B) { benchmarkCreate(10, b) }
func BenchmarkCreate100(b *testing.B) { benchmarkCreate(100, b) }
func BenchmarkCreate1000(b *testing.B) { benchmarkCreate(1000, b) }
func BenchmarkCreate10000(b *testing.B) { benchmarkCreate(10000, b) }

func BenchmarkCreate100000(b *testing.B) { benchmarkCreate(100000, b) }
func BenchmarkCreate1000000(b *testing.B) { benchmarkCreate(1000000, b) }
func BenchmarkCreate10000000(b *testing.B) { benchmarkCreate(10000000, b) }

func benchmarkCreate(limit int, b *testing.B) {
for i := 0; i < b.N; i++ {
CreateDigestFor(limit, b)
}
}

func CreateDigestFor(count int, b *testing.B) {
b.StopTimer()
reader := &Reader{limit: count}

config := &Config{
Reader: reader,
Key: []int{0},
Value: []int{1},
}

b.StartTimer()
Create(config)
}

type Csv struct {
counter int
limit int
}

type Reader struct {
counter int
limit int
}

func (r *Reader) Read(p []byte) (n int, err error) {
if r.counter == r.limit {
return 0, io.EOF
}
toRead := fmt.Sprintf("%d,%s\n", r.counter, SomeText)
r.counter++
for i, b := range []byte(toRead) {
p[i] = b
}
return len(toRead), nil
}

0 comments on commit facb093

Please sign in to comment.