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

Optimize find_first_of for one element needle #4563

Merged
merged 11 commits into from
Apr 9, 2024

Conversation

AlexGuteniev
Copy link
Contributor

@AlexGuteniev AlexGuteniev commented Apr 4, 2024

Look for /325/1 lines in the result:

Before:

---------------------------------------------------------------
Benchmark                     Time             CPU   Iterations
---------------------------------------------------------------
bm<uint8_t>/2/3            3.58 ns         2.47 ns    640000000
bm<uint8_t>/7/4            13.8 ns         11.8 ns     99555556
bm<uint8_t>/9/3            9.76 ns         7.25 ns    213333333
bm<uint8_t>/22/5           10.1 ns         8.79 ns    186666667
bm<uint8_t>/58/2           11.4 ns         10.2 ns    100000000
bm<uint8_t>/102/4          13.4 ns         11.9 ns    100000000
bm<uint8_t>/325/1          33.0 ns         27.6 ns     49777778
bm<uint8_t>/1011/11        94.6 ns         79.4 ns     19478261
bm<uint8_t>/3056/7          276 ns          222 ns      5973333
bm<uint16_t>/2/3           2.72 ns         2.25 ns    896000000
bm<uint16_t>/7/4           16.5 ns         13.3 ns     89600000
bm<uint16_t>/9/3           10.5 ns         8.80 ns    154482759
bm<uint16_t>/22/5          11.1 ns         10.8 ns    100000000
bm<uint16_t>/58/2          15.1 ns         12.6 ns    128000000
bm<uint16_t>/102/4         22.3 ns         20.1 ns     89600000
bm<uint16_t>/325/1         59.8 ns         52.7 ns     24888889
bm<uint16_t>/1011/11       3534 ns         3214 ns       471579
bm<uint16_t>/3056/7         541 ns          455 ns      2986667

After:

---------------------------------------------------------------
Benchmark                     Time             CPU   Iterations
---------------------------------------------------------------
bm<uint8_t>/2/3            2.88 ns         2.30 ns    597333333
bm<uint8_t>/7/4            13.9 ns         11.7 ns    112000000
bm<uint8_t>/9/3            9.94 ns         7.85 ns    179200000
bm<uint8_t>/22/5           10.4 ns         6.98 ns    179200000
bm<uint8_t>/58/2           11.5 ns         8.32 ns    169056604
bm<uint8_t>/102/4          13.4 ns         11.2 ns    154482759
bm<uint8_t>/325/1          5.72 ns         3.74 ns    308965517
bm<uint8_t>/1011/11        93.7 ns         85.0 ns     16000000
bm<uint8_t>/3056/7          275 ns          243 ns      5973333
bm<uint16_t>/2/3           3.51 ns         3.11 ns    471578947
bm<uint16_t>/7/4           13.9 ns         11.7 ns    100000000
bm<uint16_t>/9/3           10.8 ns         8.91 ns    128000000
bm<uint16_t>/22/5          11.3 ns         10.5 ns    100000000
bm<uint16_t>/58/2          15.3 ns         13.4 ns    112000000
bm<uint16_t>/102/4         22.2 ns         20.0 ns     64000000
bm<uint16_t>/325/1         8.40 ns         7.54 ns    194782609
bm<uint16_t>/1011/11       3369 ns         3024 ns       527059
bm<uint16_t>/3056/7         516 ns          466 ns      2986667

@AlexGuteniev AlexGuteniev requested a review from a team as a code owner April 4, 2024 08:09
@StephanTLavavej StephanTLavavej added the performance Must go faster label Apr 4, 2024
@StephanTLavavej StephanTLavavej self-assigned this Apr 4, 2024
stl/inc/algorithm Outdated Show resolved Hide resolved
benchmarks/src/find_first_of.cpp Show resolved Hide resolved
stl/inc/algorithm Outdated Show resolved Hide resolved
stl/inc/algorithm Show resolved Hide resolved
stl/inc/algorithm Outdated Show resolved Hide resolved
stl/inc/algorithm Outdated Show resolved Hide resolved
@StephanTLavavej
Copy link
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej StephanTLavavej merged commit 56ad825 into microsoft:main Apr 9, 2024
35 checks passed
@StephanTLavavej
Copy link
Member

Thanks for another awesome optimization! 😹 🚀 🪄

@AlexGuteniev AlexGuteniev deleted the first_of_one branch April 10, 2024 03:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Must go faster
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants