Message12022
Ok decided to try and benchmark this and here are the results.
Current master:
Jython 2.7.2a1+ (, Jun 27 2018, 19:16:18)
[OpenJDK 64-Bit Server VM (Oracle Corporation)] on java1.8.0_171
Type "help", "copyright", "credits" or "license" for more information.
>>> import timeit
>>> def print_int():
... print('%d' % 6235676672)
...
>>> timeit.timeit('print_int', setup="from __main__ import print_int", number=1000000000)
1.309999942779541
>>> timeit.timeit('print_int', setup="from __main__ import print_int", number=1000000000)
1.3050000667572021
>>> timeit.timeit('print_int', setup="from __main__ import print_int", number=1000000000)
1.306999921798706
>>> timeit.timeit('print_int', setup="from __main__ import print_int", number=1000000000)
1.2990000247955322
With promotion to BigInteger the suggested fix on PR 102:
Jython 2.7.2a1+ (, Jun 27 2018, 19:03:22)
[OpenJDK 64-Bit Server VM (Oracle Corporation)] on java1.8.0_171
Type "help", "copyright", "credits" or "license" for more information.
>>> import timeit
>>> execfile('bench.py')
>>> def print_int():
... print('%d' % 6235676672)
...
>>> timeit.timeit('print_int', setup="from __main__ import print_int", number=1000000000)
1.312000036239624
>>> timeit.timeit('print_int', setup="from __main__ import print_int", number=1000000000)
1.3289999961853027
>>> timeit.timeit('print_int', setup="from __main__ import print_int", number=1000000000)
1.306999921778706
>>> timeit.timeit('print_int', setup="from __main__ import print_int", number=1000000000)
1.3040001392364502
Just for interest here is CPython:
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import timeit
>>> def print_int():
... print('%d' % 6235676672)
...
>>> timeit.timeit('print_int', setup="from __main__ import print_int", number=1000000000)
9.2016921043396
>>> timeit.timeit('print_int', setup="from __main__ import print_int", number=1000000000)
9.216765880584717
>>> timeit.timeit('print_int', setup="from __main__ import print_int", number=1000000000)
9.206844091415405
That's running 1,000,000,000 (1 billion) print functions formatting an integer. Jython is fast here! Around 7 times faster than CPython.
The difference between promoting to a BigInteger and the existing system is very small <1%, and that is without adding the additional "if" required to return the string constant, so in my opinion the code simplification offered by promotion is the better solution.
Off topic: I'm kind of surprised how much Jython beats CPython by in this. JVM string handling is very fast but still there must be stuff CPython are doing badly. I would be interested if anyone know why, is this benchmark flawed somehow? The scaling with the number of repeats looks ok to me, so I don't think i'm looking at the JVM being clever somehow. |
|
Date |
User |
Action |
Args |
2018-06-27 18:34:47 | jamesmudd | set | messageid: <1530124487.59.0.56676864532.issue2672@psf.upfronthosting.co.za> |
2018-06-27 18:34:47 | jamesmudd | set | recipients:
+ jamesmudd, jeff.allen, stefan.richthofer |
2018-06-27 18:34:47 | jamesmudd | link | issue2672 messages |
2018-06-27 18:34:46 | jamesmudd | create | |
|