omaciel / fauxfactory

Generates random data for your tests.
Other
37 stars 26 forks source link

Improve execution time of some key methods #123

Closed JacobCallahan closed 2 years ago

JacobCallahan commented 2 years ago

I changed the random selection of some methods from comprehensions to uses of random.choices. Most improved by around 15%. However, gen_cjk saw a 5.5x speedup!

I then took it a bit further by moving random.seed out of each method call and into the module scope. This greatly improved the runtime of each changed method. Additionally, it should still alleviate the original concern solved with #81

Here are the observed performance changes

before
======
%timeit fauxfactory.gen_alpha()
16.2 µs ± 495 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
%timeit fauxfactory.gen_alphanumeric()
17.4 µs ± 488 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
%timeit fauxfactory.gen_cjk()
18.8 µs ± 232 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)

gen choices
===========
%timeit fauxfactory.gen_alpha()
13.7 µs ± 257 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
%timeit fauxfactory.gen_alphanumeric()
13.6 µs ± 536 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
%timeit fauxfactory.gen_cjk()
3.36 ms ± 224 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

seed once
=========
%timeit fauxfactory.gen_alpha()
2.7 µs ± 186 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
%timeit fauxfactory.gen_alphanumeric()
2.6 µs ± 31.4 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
%timeit fauxfactory.gen_cjk()
3.33 ms ± 44.1 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
codecov[bot] commented 2 years ago

Codecov Report

Merging #123 (15bcafb) into master (ba67cd7) will not change coverage. The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master      #123   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           10        10           
  Lines          517       505   -12     
=========================================
- Hits           517       505   -12     
Impacted Files Coverage Δ
fauxfactory/factories/choices.py 100.00% <100.00%> (ø)
fauxfactory/factories/dates.py 100.00% <100.00%> (ø)
fauxfactory/factories/internet.py 100.00% <100.00%> (ø)
fauxfactory/factories/strings.py 100.00% <100.00%> (ø)

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

JacobCallahan commented 2 years ago

Py 3.6 check failure looks to be unrelated to my changes and lies in the check tooling itself. Perhaps it's time to drop explicit 3.6 support and add 3.10?