go-enry / go-license-detector

Reliable project licenses detector.
Other
127 stars 36 forks source link

Preload method with benchmarks #14

Closed g4s8 closed 3 years ago

g4s8 commented 3 years ago

Fixes #13 - added preload method to initialize database without performing any license check. Added two benchmarks to compare the difference between calls with and without preload.

g4s8 commented 3 years ago

Benchmark results on my laptop:

$ go test -bench="BenchmarkDetect$" ./licensedb -run=BenchmarkDetect
goos: linux
goarch: amd64
pkg: github.com/go-enry/go-license-detector/v4/licensedb
cpu: Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
BenchmarkDetect-12            1 2183395428 ns/op
PASS
ok      github.com/go-enry/go-license-detector/v4/licensedb 2.344s

$ go test -bench="BenchmarkDetectWithPreload$" ./licensedb -run=BenchmarkDetectWithPreload
goos: linux
goarch: amd64
pkg: github.com/go-enry/go-license-detector/v4/licensedb
cpu: Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
BenchmarkDetectWithPreload-12            76  15373506 ns/op
PASS
ok      github.com/go-enry/go-license-detector/v4/licensedb 3.444s
g4s8 commented 3 years ago

@bzz could you please check this PR?

g4s8 commented 3 years ago

@bzz hi, any chance to review this PR?

g4s8 commented 3 years ago

LGTM, sans a minor API doc clarification.

Windows test failures have nothing to do with the change.

Thank you for adding this!

@bzz thanks, fixed in the last commit https://github.com/go-enry/go-license-detector/pull/14/commits/6403a23e656acb8434697c4bdcd4720ec2e209a1