Skip to content

Micro-optimization: faster split_selfies#137

Open
rhjohnstone wants to merge 4 commits intoaspuru-guzik-group:masterfrom
rhjohnstone:faster-split
Open

Micro-optimization: faster split_selfies#137
rhjohnstone wants to merge 4 commits intoaspuru-guzik-group:masterfrom
rhjohnstone:faster-split

Conversation

@rhjohnstone
Copy link
Copy Markdown

Just for fun, I implemented sf.split_selfies slightly differently, which is 2--4x faster on the selfies I tested. These are valuable microseconds we're saving!

All tox tests pass, and I added a new test to confirm correctness and benchmarks comparing the two split methods against 3 different datasets: a list of regular selfies, a list of selfies containing a dot, and a list of much longer selfies. Here are the benchmarks from the 3.10 tests, and they all look like this:

------------------------------------------------------------------------------------------------------ benchmark 'dots': 2 tests ------------------------------------------------------------------------------------------------------
Name (time in us)                                               Min                   Max                Mean             StdDev              Median         
       IQR            Outliers  OPS (Kops/s)            Rounds  Iterations
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_compare_split_methods[split_selfies-dots]              89.3000 (1.0)        719.9000 (1.0)       96.9626 (1.0)      23.3265 (1.0)       91.8000 (1.0)       2.4000 (1.0)       490;936       10.3133 (1.0)        8681           1
test_compare_split_methods[_split_selfies_legacy-dots]     237.8000 (2.66)     1,235.5000 (1.72)     259.4146 (2.68)     63.0037 (2.70)     245.2000 (2.67)     12.7000 (5.29)      142;249        3.8548 (0.37)       2646           1
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

-------------------------------------------------------------------------------------------------------- benchmark 'long': 2 tests ---------------------------------------------------------------------------------------------------------
Name (time in us)                                                 Min                   Max                  Mean              StdDev                Median                IQR            Outliers         OPS            Rounds  Iterations
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_compare_split_methods[split_selfies-long]               340.3000 (1.0)      1,156.1000 (1.0)        365.6551 (1.0)       69.9039 (1.0)        350.9000 (1.0)      10.9000 (1.0)       116;287  2,734.8174 (1.0)        2422           1
test_compare_split_methods[_split_selfies_legacy-long]     1,307.6000 (3.84)     2,920.7000 (2.53)     1,405.9733 (3.85)     193.6538 (2.77)     1,353.0500 (3.86)     69.4000 (6.37)        54;85    711.2511 (0.26)        726           1
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------- benchmark 'regular': 2 tests ----------------------------------------------------------------------------------------------------
Name (time in us)                                                  Min                 Max                Mean             StdDev              Median               IQR            Outliers  OPS (Kops/s)            Rounds  Iterations
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_compare_split_methods[split_selfies-regular]              51.4000 (1.0)      285.1000 (1.0)       58.4986 (1.0)      15.8357 (1.0)       54.9000 (1.0)      2.0000 (1.0)      755;1375       17.0944 (1.0)       12346           1
test_compare_split_methods[_split_selfies_legacy-regular]     117.9000 (2.29)     943.0000 (3.31)     130.6158 (2.23)     26.6549 (1.68)     124.8000 (2.27)     5.5000 (2.75)      481;798        7.6560 (0.45)       7687           1
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

@MarioKrenn6240
Copy link
Copy Markdown
Collaborator

Thank you. Give us some time to check and comment.

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.

2 participants