-
Notifications
You must be signed in to change notification settings - Fork 232
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
feat(lang/fastrand): add Read([]byte) function #90
feat(lang/fastrand): add Read([]byte) function #90
Conversation
f158a7a
to
48e4053
Compare
b750805
to
c75ec65
Compare
Thank you! Guess we could use the Here is an example. // Read generates len(p) random bytes and writes them into p.
// It always returns len(p) and a nil error. And it is safe
// for concurrent use.
func Read(p []byte) (n int, err error) {
l := len(p)
if l >= 4 {
i := 0
uint32p := *(*[]uint32)(unsafe.Pointer(&p))
for l >= 4 {
uint32p[i] = Uint32()
i++
l -= 4
}
}
if l > 0 {
r := Uint32()
for l > 0 {
p[len(p)-l] = byte(r >> (l * 8))
l--
}
}
return len(p), nil
} Performance comparison.
Use local |
Great! So what should I do? Close this MR or just update my commit ? |
Just update this PR please, I can implement the complicated version in the next PR. |
c75ec65
to
8161583
Compare
Updated. Thanks for review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
* release: 20210913 (#83) (#88) * feat: circuitbreaker.panel use skipmap (#78) * fix(metainfo): fix misuse of append (#79) * fix(lscq): add write barrier for LSCQ Pointer (#80) * feat(metainfo): improve backward APIs (#81) * release: 20210913 (#83) (#93) * feat: circuitbreaker.panel use skipmap (#78) * fix(metainfo): fix misuse of append (#79) * fix(lscq): add write barrier for LSCQ Pointer (#80) * feat(metainfo): improve backward APIs (#81) * chore(skipmap,skipset): remove duplicated code generation declaration (#87) * fix(lscq): cas2 use runtime.noescape (#94) * feat: add fastrand.Read() (#90) Co-authored-by: liyichao <[email protected]> * doc: add badge to link to godoc (#99) * ci: skip golang related workflows when there are only doc changes (#101) * ci: add workflow for feishu/lark notification (#100) * ci: add workflow for feishu/lark notification * ci: fix typo * ci: also send feishu notification on issue opened Co-authored-by: Jonathan Lu <[email protected]> * feat(metainfo): define standard for backward prefix (#102) * feat(fastrand): support Read,Shuffle,Perm (#103) * feat(fastrand): Read remove temp buffer (#104) * ci: add github workflow for performance regression check (#95) * ci: add github workflow for performance regression check Comment "/benchdiff" to trigger this check * ci: add comments to pr-benchdiff.yml * ci: report benchdiff result to PR_HEAD's check run * ci: various changes - support "pull_reqeust" event - filter deleted go packages - post a comment on job started - post a comment on job failed * ci: let xargs ignore empty line * ci: skip benchdiff when there are only doc changes * ci: set -x for debugging * ci: make sure we are using github default branch as baseline * ci: set benchtime=1s for benchdiff * chore: add github issue forms (#105) * test(lang/syncx): add benchmark for RWMutex (#89) * fix(xxhash3): add fallback to fix panic occurs on non avx2, non sse2 machine (#108) Co-authored-by: Ye Li <[email protected]> * feat: add zset (#98) * feat: add zset * chore(zset): update comment * docs(zset): add readme * chore: some code style fixes * chore(zset): rename Float64RangeOpt -> RangeOpt * chore(zset): comment style fixes * chore(zset): add a todo about maxLevel * chore(zset): another comment fix * chore(zset): move skiplist impl to another file * chore(zset): add license header for opt.go * chore: add myself as zset's CODEOWNER * zset: don't use z.Range(0, z.Len()-1) * doc: remove redundant section * fix(zset): break when key is not exist * chore(zset): simplify func name * chore(zset): update cheatsheet * chore(zset): meaningful const * refactor(zset): optionalArray.init() * docs: update zset readme * docs(zset): also add @zhangyunhao116 as code owner * docs(zset): some grammar fixes * docs: fix docs typo (#109) * feat: auto tuning gc (#112) * feat: auto tuning gc * doc: gctuner * fix: gctuner tests data race (#113) * fix: gctuner tests data race * chore: add owner * chore(ci): use self-hosted runner (#114) * chore(ci): use self-hosted runner * fix lint Co-authored-by: Shengyu Zhang <[email protected]> Co-authored-by: ziposcar <[email protected]> Co-authored-by: liyichao <[email protected]> Co-authored-by: Shengyu Zhang <[email protected]> Co-authored-by: Jonathan Lu <[email protected]> Co-authored-by: Pure White <[email protected]> Co-authored-by: lyeeeeee <[email protected]> Co-authored-by: Ye Li <[email protected]> Co-authored-by: chyroc <[email protected]> Co-authored-by: Joway <[email protected]> Co-authored-by: Joway <[email protected]>
What
This PR add a new function
func Read([]byte) (n int, err error)
for fastrand package. It has the same signature withmath/rand.Read
andmath/rand.(*Rand).Read
.Why
fastrand
is so good that I want to use it everywhere~And in my benchmark, it's at least 30% faster than
math/rand.(*Rand).Read
in single goroutine.How
Just like
math/rand.Read
.