Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor:refactor RandomString function #524

Merged
merged 11 commits into from
Sep 19, 2024
Merged

Conversation

pigwantacat
Copy link
Contributor

@pigwantacat pigwantacat commented Aug 22, 2024

reference resources:How to generate a random string of a fixed length in Go?

func BenchmarkApproach1(b *testing.B) {
	for i := 0; i < b.N; i++ {
		_ = RandomString(1<<10, lo.AlphanumericCharset)
	}
}

func BenchmarkApproach2(b *testing.B) {
	for i := 0; i < b.N; i++ {
		_ = lo.RandomString(1<<10, lo.AlphanumericCharset)
	}
}
$ go test -benchmem -benchtime=5s -bench .
goos: windows
goarch: amd64
pkg: mytttttt
cpu: Intel(R) Core(TM) i5-10400 CPU @ 2.90GHz
BenchmarkApproach1-12            1000000              5423 ns/op            1024 B/op          1 allocs/op
BenchmarkApproach2-12             292579             20485 ns/op            5248 B/op          2 allocs/op
PASS
ok      mytttttt        12.160s

@samber
Copy link
Owner

samber commented Sep 11, 2024

that's cool!

string.go Outdated Show resolved Hide resolved
string.go Outdated Show resolved Hide resolved
string.go Show resolved Hide resolved
string.go Show resolved Hide resolved
string.go Outdated Show resolved Hide resolved
string.go Show resolved Hide resolved
string.go Outdated Show resolved Hide resolved
string.go Show resolved Hide resolved
@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 84.61538% with 6 lines in your changes missing coverage. Please review.

Project coverage is 94.33%. Comparing base (bc0037c) to head (e8bb837).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
string.go 84.61% 4 Missing and 2 partials ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #524      +/-   ##
==========================================
- Coverage   94.48%   94.33%   -0.15%     
==========================================
  Files          17       17              
  Lines        2757     2790      +33     
==========================================
+ Hits         2605     2632      +27     
- Misses        150      154       +4     
- Partials        2        4       +2     
Flag Coverage Δ
unittests 94.33% <84.61%> (-0.15%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@samber samber merged commit a6a53e1 into samber:master Sep 19, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants