Commit 046c84e
committed
Use Fraction's private attributes in arithmetic methods
That's slightly faster for small components.
Before:
$ ./python -m timeit -r11 -s 'from fractions import Fraction as F' \
-s 'a = F(10, 3)' -s 'b = F(6, 5)' 'a + b'
20000 loops, best of 11: 12.1 usec per loop
$ ./python -m timeit -r11 -s 'from fractions import Fraction as F' \
-s 'a = F(10, 3)' -s 'b = 7' 'a + b'
20000 loops, best of 11: 11.4 usec per loop
After:
$ ./python -m timeit -r11 -s 'from fractions import Fraction as F' \
-s 'a = F(10, 3)' -s 'b = F(6, 5)' 'a + b'
50000 loops, best of 11: 9.74 usec per loop
$ ./python -m timeit -r11 -s 'from fractions import Fraction as F' \
-s 'a = F(10, 3)' -s 'b = 7' 'a + b'
20000 loops, best of 11: 16.5 usec per loop
On the master:
$ ./python -m timeit -r11 -s 'from fractions import Fraction as F' \
-s 'a = F(10, 3)' -s 'b = F(6, 5)' 'a + b'
50000 loops, best of 11: 9.61 usec per loop
$ ./python -m timeit -r11 -s 'from fractions import Fraction as F' \
-s 'a = F(10, 3)' -s 'b = 7' 'a + b'
50000 loops, best of 11: 9.11 usec per loop1 parent 430e476 commit 046c84e
1 file changed
+12
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
355 | 355 | | |
356 | 356 | | |
357 | 357 | | |
358 | | - | |
| 358 | + | |
359 | 359 | | |
| 360 | + | |
| 361 | + | |
360 | 362 | | |
361 | 363 | | |
362 | 364 | | |
| |||
367 | 369 | | |
368 | 370 | | |
369 | 371 | | |
370 | | - | |
371 | | - | |
| 372 | + | |
372 | 373 | | |
| 374 | + | |
| 375 | + | |
373 | 376 | | |
374 | 377 | | |
375 | 378 | | |
| |||
444 | 447 | | |
445 | 448 | | |
446 | 449 | | |
447 | | - | |
448 | | - | |
| 450 | + | |
| 451 | + | |
449 | 452 | | |
450 | 453 | | |
451 | 454 | | |
| |||
465 | 468 | | |
466 | 469 | | |
467 | 470 | | |
468 | | - | |
469 | | - | |
| 471 | + | |
| 472 | + | |
470 | 473 | | |
471 | 474 | | |
472 | 475 | | |
| |||
477 | 480 | | |
478 | 481 | | |
479 | 482 | | |
480 | | - | |
481 | | - | |
| 483 | + | |
| 484 | + | |
482 | 485 | | |
483 | 486 | | |
484 | 487 | | |
| |||
0 commit comments