Skip to content

Refactor by float conversion steps to macro and apply to fsum().#11698

Merged
rhettinger merged 1 commit into
python:masterfrom
rhettinger:fast_as_float
Jan 30, 2019
Merged

Refactor by float conversion steps to macro and apply to fsum().#11698
rhettinger merged 1 commit into
python:masterfrom
rhettinger:fast_as_float

Conversation

@rhettinger

Copy link
Copy Markdown
Contributor
  • Clean-up code by moving float conversion steps into a macro.
  • Apply the macro to fsum() giving a 20% speed-up for float inputs and a 40% speed-up for integer inputs.

Baseline timings:

$ ./python.exe -m timeit -r 11 -s 'from math import fsum' -s 'seq=list(map(float, range(100)))' 'fsum(seq)'
200000 loops, best of 11: 1.27 usec per loop
./python.exe -m timeit -r 11 -s 'from math import fsum' -s 'seq=list(map(int, range(100)))' 'fsum(seq)'
100000 loops, best of 11: 2.26 usec per loop

Patched timings:

$ ./python.exe -m timeit -r 11 -s 'from math import fsum' -s 'seq=list(map(float, range(100)))' 'fsum(seq)'
200000 loops, best of 11: 1 usec per loop
$ ./python.exe -m timeit -r 11 -s 'from math import fsum' -s 'seq=list(map(int, range(100)))' 'fsum(seq)'
200000 loops, best of 11: 1.36 usec per loop

@rhettinger rhettinger added performance Performance or resource usage skip issue skip news labels Jan 29, 2019
@rhettinger
rhettinger merged commit cfd735e into python:master Jan 30, 2019
@rhettinger
rhettinger deleted the fast_as_float branch January 30, 2019 04:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Performance or resource usage skip issue skip news

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants