-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0feac4
commit 7b132f5
Showing
3 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
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
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
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 | |
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
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 | ||
} |