-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
3 changed files
with
55 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
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,45 @@ | ||
package licensedb | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/go-enry/go-license-detector/v4/licensedb/filer" | ||
) | ||
|
||
func BenchmarkDetect(b *testing.B) { | ||
f := pwdFiler() | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
_, err := Detect(f) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
} | ||
|
||
func BenchmarkDetectWithPreload(b *testing.B) { | ||
f := pwdFiler() | ||
Preload() | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
_, err := Detect(f) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
} | ||
|
||
func pwdFiler() filer.Filer { | ||
pwd, err := os.Getwd() | ||
if err != nil { | ||
panic(err) | ||
} | ||
root := filepath.Dir(pwd) | ||
f, err := filer.FromDirectory(root) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return f | ||
} |