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

perf(fastrand): optimize Read #123

Merged
merged 4 commits into from
Mar 23, 2022
Merged

perf(fastrand): optimize Read #123

merged 4 commits into from
Mar 23, 2022

Conversation

zhangyunhao116
Copy link
Member

Use wyrand, see https://github.com/wangyi-fudan/wyhash.

name                                old time/op  new time/op  delta
SingleCore/math/rand-Uint32()-16    10.8ns ± 0%  10.8ns ± 0%     ~     (p=0.913 n=7+10)
SingleCore/fast-rand-Uint32()-16    2.26ns ± 0%  2.25ns ± 0%     ~     (p=0.015 n=10+10)
SingleCore/math/rand-Uint64()-16    11.1ns ± 0%  11.1ns ± 0%     ~     (p=0.014 n=10+8)
SingleCore/fast-rand-Uint64()-16    5.03ns ± 0%  4.75ns ± 0%   -5.50%  (p=0.000 n=10+9)
SingleCore/math/rand-Read1000-16     682ns ± 0%   682ns ± 0%     ~     (p=0.927 n=10+10)
SingleCore/fast-rand-Read1000-16     298ns ± 1%   150ns ± 0%  -49.69%  (p=0.000 n=10+9)
MultipleCore/math/rand-Uint32()-16   114ns ± 3%   113ns ± 4%     ~     (p=0.306 n=10+10)
MultipleCore/fast-rand-Uint32()-16  0.18ns ± 1%  0.18ns ± 2%     ~     (p=0.006 n=9+10)
MultipleCore/math/rand-Uint64()-16   115ns ± 6%   118ns ± 3%     ~     (p=0.018 n=10+9)
MultipleCore/fast-rand-Uint64()-16  0.39ns ± 1%  0.38ns ± 0%   -1.55%  (p=0.000 n=10+8)
MultipleCore/math/rand-Read1000-16  1.02µs ± 3%  1.03µs ± 4%     ~     (p=0.644 n=10+10)
MultipleCore/fast-rand-Read1000-16   112ns ± 0%   102ns ± 1%   -9.38%  (p=0.000 n=10+10)

name                                old time/op  new time/op  delta
SingleCore/math/rand-Uint32()-16    10.8ns ± 0%  10.8ns ± 0%     ~     (p=0.913 n=7+10)
SingleCore/fast-rand-Uint32()-16    2.26ns ± 0%  2.25ns ± 0%     ~     (p=0.015 n=10+10)
SingleCore/math/rand-Uint64()-16    11.1ns ± 0%  11.1ns ± 0%     ~     (p=0.014 n=10+8)
SingleCore/fast-rand-Uint64()-16    5.03ns ± 0%  4.75ns ± 0%   -5.50%  (p=0.000 n=10+9)
SingleCore/math/rand-Read1000-16     682ns ± 0%   682ns ± 0%     ~     (p=0.927 n=10+10)
SingleCore/fast-rand-Read1000-16     298ns ± 1%   150ns ± 0%  -49.69%  (p=0.000 n=10+9)
MultipleCore/math/rand-Uint32()-16   114ns ± 3%   113ns ± 4%     ~     (p=0.306 n=10+10)
MultipleCore/fast-rand-Uint32()-16  0.18ns ± 1%  0.18ns ± 2%     ~     (p=0.006 n=9+10)
MultipleCore/math/rand-Uint64()-16   115ns ± 6%   118ns ± 3%     ~     (p=0.018 n=10+9)
MultipleCore/fast-rand-Uint64()-16  0.39ns ± 1%  0.38ns ± 0%   -1.55%  (p=0.000 n=10+8)
MultipleCore/math/rand-Read1000-16  1.02µs ± 3%  1.03µs ± 4%     ~     (p=0.644 n=10+10)
MultipleCore/fast-rand-Read1000-16   112ns ± 0%   102ns ± 1%   -9.38%  (p=0.000 n=10+10)
@github-actions
Copy link

Benchdiff

Runs: Benchdiff #33

Job is started.

@github-actions
Copy link

Benchdiff

Command: go test ./lang/fastrand -run '^$' -bench . -count 10 -benchtime 1s -cpu 4 -benchmem
HEAD: cf61946
Base: 1372042
Runs: Benchdiff #33
Degraded: true

Results

pkg: github.com/bytedance/gopkg/lang/fastrand
goos: linux
goarch: amd64

name old time/op (ns/op) ± new time/op (ns/op) ± delta ±
SingleCore/math/rand-Uint32()-4 16.2022 0% 16.2062 0% ~ (p=0.487 n=9+8)
SingleCore/fast-rand-Uint32()-4 2.32233 0% 2.3941 0% +3.09% (p=0.000 n=9+10)
SingleCore/math/rand-Uint64()-4 17.1778 0% 17.17 0% ~ (p=0.206 n=9+9)
SingleCore/fast-rand-Uint64()-4 5.5175 0% 5.5178 0% ~ (p=0.144 n=8+10)
SingleCore/math/rand-Read1000-4 903.6 8% 886.21 0% ~ (p=0.068 n=9+10)
SingleCore/fast-rand-Read1000-4 398.975 1% 229.04 0% -42.59% (p=0.000 n=8+10)
MultipleCore/math/rand-Uint32()-4 75.482 2% 72.552 6% -3.88% (p=0.029 n=10+10)
MultipleCore/fast-rand-Uint32()-4 0.608738 0% 0.624056 0% +2.52% (p=0.000 n=8+9)
MultipleCore/math/rand-Uint64()-4 75.926 5% 75.779 3% ~ (p=0.631 n=10+10)
MultipleCore/fast-rand-Uint64()-4 1.40067 0% 1.40056 0% ~ (p=0.689 n=9+9)
MultipleCore/math/rand-Read1000-4 927.344 4% 933.65 3% ~ (p=0.150 n=9+10)
MultipleCore/fast-rand-Read1000-4 158.58 1% 247.25 2% +55.91% (p=0.000 n=10+10)
name old alloc/op (B/op) ± new alloc/op (B/op) ± delta ±
SingleCore/math/rand-Uint32()-4 0 0 ~ (all equal)
SingleCore/fast-rand-Uint32()-4 0 0 ~ (all equal)
SingleCore/math/rand-Uint64()-4 0 0 ~ (all equal)
SingleCore/fast-rand-Uint64()-4 0 0 ~ (all equal)
SingleCore/math/rand-Read1000-4 0 0 ~ (all equal)
SingleCore/fast-rand-Read1000-4 0 0 ~ (all equal)
MultipleCore/math/rand-Uint32()-4 0 0 ~ (all equal)
MultipleCore/fast-rand-Uint32()-4 0 0 ~ (all equal)
MultipleCore/math/rand-Uint64()-4 0 0 ~ (all equal)
MultipleCore/fast-rand-Uint64()-4 0 0 ~ (all equal)
MultipleCore/math/rand-Read1000-4 0 0 ~ (all equal)
MultipleCore/fast-rand-Read1000-4 0 0 ~ (all equal)
name old allocs/op (allocs/op) ± new allocs/op (allocs/op) ± delta ±
SingleCore/math/rand-Uint32()-4 0 0 ~ (all equal)
SingleCore/fast-rand-Uint32()-4 0 0 ~ (all equal)
SingleCore/math/rand-Uint64()-4 0 0 ~ (all equal)
SingleCore/fast-rand-Uint64()-4 0 0 ~ (all equal)
SingleCore/math/rand-Read1000-4 0 0 ~ (all equal)
SingleCore/fast-rand-Read1000-4 0 0 ~ (all equal)
MultipleCore/math/rand-Uint32()-4 0 0 ~ (all equal)
MultipleCore/fast-rand-Uint32()-4 0 0 ~ (all equal)
MultipleCore/math/rand-Uint64()-4 0 0 ~ (all equal)
MultipleCore/fast-rand-Uint64()-4 0 0 ~ (all equal)
MultipleCore/math/rand-Read1000-4 0 0 ~ (all equal)
MultipleCore/fast-rand-Read1000-4 0 0 ~ (all equal)

@PureWhiteWu
Copy link
Collaborator

要不 ci 顺便修一下?看起来加个 -y 就行了?

Copy link
Member

@SilverRainZ SilverRainZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zhangyunhao116 zhangyunhao116 merged commit 0b4f238 into develop Mar 23, 2022
@zhangyunhao116 zhangyunhao116 deleted the perf/fastrand branch March 23, 2022 13:15
joway pushed a commit to joway/gopkg that referenced this pull request Apr 17, 2024
use wyrand, see https://github.com/wangyi-fudan/wyhash.

name                                old time/op  new time/op  delta
SingleCore/math/rand-Uint32()-16    10.8ns ± 0%  10.8ns ± 0%     ~     (p=0.913 n=7+10)
SingleCore/fast-rand-Uint32()-16    2.26ns ± 0%  2.25ns ± 0%     ~     (p=0.015 n=10+10)
SingleCore/math/rand-Uint64()-16    11.1ns ± 0%  11.1ns ± 0%     ~     (p=0.014 n=10+8)
SingleCore/fast-rand-Uint64()-16    5.03ns ± 0%  4.75ns ± 0%   -5.50%  (p=0.000 n=10+9)
SingleCore/math/rand-Read1000-16     682ns ± 0%   682ns ± 0%     ~     (p=0.927 n=10+10)
SingleCore/fast-rand-Read1000-16     298ns ± 1%   150ns ± 0%  -49.69%  (p=0.000 n=10+9)
MultipleCore/math/rand-Uint32()-16   114ns ± 3%   113ns ± 4%     ~     (p=0.306 n=10+10)
MultipleCore/fast-rand-Uint32()-16  0.18ns ± 1%  0.18ns ± 2%     ~     (p=0.006 n=9+10)
MultipleCore/math/rand-Uint64()-16   115ns ± 6%   118ns ± 3%     ~     (p=0.018 n=10+9)
MultipleCore/fast-rand-Uint64()-16  0.39ns ± 1%  0.38ns ± 0%   -1.55%  (p=0.000 n=10+8)
MultipleCore/math/rand-Read1000-16  1.02µs ± 3%  1.03µs ± 4%     ~     (p=0.644 n=10+10)
MultipleCore/fast-rand-Read1000-16   112ns ± 0%   102ns ± 1%   -9.38%  (p=0.000 n=10+10)
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.

3 participants