Skip to content

Instantly share code, notes, and snippets.

@sholloway
Last active July 5, 2024 15:35
Show Gist options
  • Save sholloway/21dad114dca0d22db8410fef36b449db to your computer and use it in GitHub Desktop.
Save sholloway/21dad114dca0d22db8410fef36b449db to your computer and use it in GitHub Desktop.
Python Numeric Types Performance Benchmarks
-------------------------------------------------------------------------------- benchmark 'Test Addition': 4 tests --------------------------------------------------------------------------------
Name (time in ns) Min Mean Max Median StdDev IQR Outliers OPS (Mops/s) Rounds Iterations
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_ints 32.2199 (1.0) 33.8687 (1.0) 361.6667 (1.0) 33.8866 (1.0) 3.5444 (1.0) 1.1133 (1.0) 882;2464 29.5258 (1.0) 199999 150
test_floats 33.6203 (1.04) 35.9602 (1.06) 3,640.2276 (10.07) 35.3449 (1.04) 22.5287 (6.36) 1.1517 (1.03) 801;3761 27.8085 (0.94) 198334 145
test_decimals 52.9096 (1.64) 56.9352 (1.68) 2,949.5900 (8.16) 55.4201 (1.64) 33.1304 (9.35) 1.6700 (1.50) 1319;2718 17.5638 (0.59) 184605 100
test_fractions 624.9757 (19.40) 768.7710 (22.70) 54,167.0015 (149.77) 750.0057 (22.13) 259.8340 (73.31) 41.9677 (37.70) 158;2005 1.3008 (0.04) 188967 1
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------- benchmark 'Test Ceil': 4 tests --------------------------------------------------------------------------------
Name (time in ns) Min Mean Max Median StdDev IQR Outliers OPS (Mops/s) Rounds Iterations
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_floats 32.5341 (1.0) 35.1001 (1.0) 6,167.8081 (10.81) 33.6779 (1.0) 33.8431 (5.40) 0.8564 (1.0) 1084;4571 28.4900 (1.0) 199999 146
test_ints 54.9998 (1.69) 57.8993 (1.65) 999.5897 (1.75) 57.9201 (1.72) 6.2724 (1.0) 1.6700 (1.95) 430;2005 17.2714 (0.61) 170213 100
test_decimals 109.7898 (3.37) 112.5169 (3.21) 570.6248 (1.0) 111.0401 (3.30) 8.6254 (1.38) 3.1249 (3.65) 541;740 8.8876 (0.31) 43875 200
test_fractions 162.0798 (4.98) 168.1966 (4.79) 1,176.6702 (2.06) 165.0001 (4.90) 11.7034 (1.87) 8.7399 (10.21) 739;401 5.9454 (0.21) 57831 100
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------- benchmark 'Test Division': 4 tests -------------------------------------------------------------------------------
Name (time in ns) Min Mean Max Median StdDev IQR Outliers OPS (Mops/s) Rounds Iterations
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_floats 34.0351 (1.0) 36.0212 (1.0) 5,502.6411 (14.33) 34.9156 (1.0) 35.1515 (15.98) 0.8805 (2.79) 458;3793 27.7615 (1.0) 199999 142
test_ints 36.5383 (1.07) 37.5791 (1.04) 383.9767 (1.0) 37.5001 (1.07) 2.2002 (1.0) 0.3157 (1.0) 1585;20570 26.6106 (0.96) 198334 130
test_decimals 79.1601 (2.33) 81.8910 (2.27) 677.4999 (1.76) 81.2497 (2.33) 5.1440 (2.34) 2.5000 (7.92) 1112;1225 12.2114 (0.44) 121213 100
test_fractions 672.8980 (19.77) 707.5471 (19.64) 2,139.6001 (5.57) 706.2481 (20.23) 25.4648 (11.57) 16.6969 (52.89) 2069;881 1.4133 (0.05) 55945 20
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------- benchmark 'Test Equality': 4 tests --------------------------------------------------------------------------------
Name (time in ns) Min Mean Max Median StdDev IQR Outliers OPS (Mops/s) Rounds Iterations
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_ints 31.8624 (1.0) 33.5263 (1.0) 1,607.0264 (1.0) 33.4964 (1.0) 7.1765 (1.0) 1.0854 (1.06) 543;4907 29.8273 (1.0) 198334 153
test_floats 32.4686 (1.02) 34.4452 (1.03) 3,554.3103 (2.21) 34.1932 (1.02) 11.8689 (1.65) 1.1517 (1.12) 508;3194 29.0316 (0.97) 195122 145
test_decimals 39.9674 (1.25) 42.2742 (1.26) 6,587.7396 (4.10) 41.6667 (1.24) 32.5956 (4.54) 1.0250 (1.0) 544;8802 23.6551 (0.79) 198373 123
test_fractions 207.9760 (6.53) 284.7743 (8.49) 41,041.9889 (25.54) 291.9696 (8.72) 155.7961 (21.71) 42.0259 (41.00) 108;681 3.5116 (0.12) 104352 1
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------ benchmark 'Test Exponential': 4 tests -------------------------------------------------------------------------------
Name (time in ns) Min Mean Max Median StdDev IQR Outliers OPS (Mops/s) Rounds Iterations
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_ints 37.7323 (1.0) 44.3823 (1.0) 16,941.9291 (24.99) 39.7008 (1.0) 100.2408 (25.64) 2.2916 (1.43) 1090;2965 22.5315 (1.0) 196733 127
test_floats 46.8745 (1.24) 49.1748 (1.11) 677.8847 (1.0) 49.2789 (1.24) 3.9099 (1.0) 1.6052 (1.0) 671;1052 20.3356 (0.90) 198337 104
test_decimals 113.3297 (3.00) 121.7733 (2.74) 1,112.0801 (1.64) 121.6697 (3.06) 10.4316 (2.67) 3.7497 (2.34) 310;600 8.2120 (0.36) 82475 100
test_fractions 541.9715 (14.36) 662.8037 (14.93) 88,167.0276 (130.06) 667.0016 (16.80) 324.9885 (83.12) 41.9677 (26.15) 39;1435 1.5087 (0.07) 97163 1
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------- benchmark 'Test Floor': 4 tests --------------------------------------------------------------------------------
Name (time in ns) Min Mean Max Median StdDev IQR Outliers OPS (Mops/s) Rounds Iterations
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_floats 30.9807 (1.0) 31.9320 (1.0) 430.2886 (1.0) 31.7821 (1.0) 3.8339 (1.0) 0.2690 (462.18) 564;17340 31.3165 (1.0) 195122 156
test_ints 54.9998 (1.78) 56.4888 (1.77) 762.9202 (1.77) 56.2501 (1.77) 4.3133 (1.13) 0.0006 (1.0) 645;61921 17.7026 (0.57) 176492 100
test_decimals 107.7101 (3.48) 109.7486 (3.44) 609.5850 (1.42) 108.7500 (3.42) 7.5610 (1.97) 0.6249 (>1000.0) 671;6546 9.1117 (0.29) 45978 200
test_fractions 137.9097 (4.45) 145.1926 (4.55) 2,229.9995 (5.18) 144.5902 (4.55) 17.2107 (4.49) 7.0903 (>1000.0) 361;951 6.8874 (0.22) 66850 100
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------- benchmark 'Test From String': 4 tests ----------------------------------------------------------------------------------
Name (time in ns) Min Mean Max Median StdDev IQR Outliers OPS (Kops/s) Rounds Iterations
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_floats 54.1698 (1.0) 56.2454 (1.0) 1,052.0802 (1.88) 55.4201 (1.0) 6.1118 (1.0) 0.4109 (1.0) 1021;36104 17,779.2309 (1.0) 172683 100
test_ints 59.5796 (1.10) 62.1641 (1.11) 733.3403 (1.31) 61.2496 (1.11) 10.9935 (1.80) 0.8405 (2.05) 822;14416 16,086.4647 (0.90) 161057 100
test_decimals 88.9599 (1.64) 92.5935 (1.65) 560.6250 (1.0) 92.2949 (1.67) 7.5555 (1.24) 2.5053 (6.10) 377;1218 10,799.8960 (0.61) 52403 200
test_fractions 1,499.9532 (27.69) 1,684.2076 (29.94) 70,957.9908 (126.57) 1,625.0415 (29.32) 823.6762 (134.77) 42.0259 (102.27) 107;2601 593.7510 (0.03) 23100 1
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------- benchmark 'Test Initialization': 4 tests -----------------------------------------------------------------------------
Name (time in ns) Min Mean Max Median StdDev IQR Outliers OPS (Mops/s) Rounds Iterations
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_floats 29.0179 (1.0) 30.4791 (1.0) 839.7855 (1.0) 30.0119 (1.0) 4.1140 (1.0) 0.9885 (1.0) 623;5141 32.8093 (1.0) 198373 168
test_ints 40.9782 (1.41) 95.5402 (3.13) 11,875.0031 (14.14) 83.0041 (2.77) 66.2580 (16.11) 41.9677 (42.46) 148;103 10.4668 (0.32) 75948 1
test_decimals 207.9760 (7.17) 292.0269 (9.58) 42,708.9981 (50.86) 291.9696 (9.73) 264.8891 (64.39) 42.0259 (42.52) 189;961 3.4243 (0.10) 78685 1
test_fractions 250.0019 (8.62) 394.5124 (12.94) 43,874.9557 (52.25) 375.0320 (12.50) 272.8940 (66.33) 41.0364 (41.51) 76;1158 2.5348 (0.08) 140351 1
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------- benchmark 'Test Multiplication': 4 tests -----------------------------------------------------------------------------
Name (time in ns) Min Mean Max Median StdDev IQR Outliers OPS (Mops/s) Rounds Iterations
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_ints 32.8152 (1.0) 34.3719 (1.0) 475.4589 (1.08) 34.5339 (1.0) 2.8862 (1.0) 0.8564 (2.09) 894;3771 29.0935 (1.0) 198334 146
test_floats 33.6282 (1.02) 35.3614 (1.03) 440.1788 (1.0) 34.8215 (1.01) 5.0928 (1.76) 1.1928 (2.91) 672;4336 28.2794 (0.97) 199999 140
test_decimals 52.9195 (1.61) 54.6882 (1.59) 583.7501 (1.33) 54.1698 (1.57) 4.7291 (1.64) 0.4104 (1.0) 1530;24398 18.2855 (0.63) 183184 100
test_fractions 667.0016 (20.33) 810.8374 (23.59) 31,124.9751 (70.71) 792.0316 (22.93) 174.0419 (60.30) 41.0364 (100.00) 190;1201 1.2333 (0.04) 94859 1
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------- benchmark 'Test Round': 4 tests -------------------------------------------------------------------------------------
Name (time in ns) Min Mean Max Median StdDev IQR Outliers OPS (Kops/s) Rounds Iterations
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_ints 55.4096 (1.0) 56.9561 (1.0) 5,878.7502 (5.71) 56.2501 (1.0) 19.0952 (2.01) 0.4197 (1.0) 283;27327 17,557.3912 (1.0) 175162 100
test_decimals 107.0899 (1.93) 109.1969 (1.92) 1,030.4200 (1.0) 108.7500 (1.93) 9.4841 (1.0) 0.8196 (1.95) 344;6724 9,157.7660 (0.52) 91601 100
test_floats 171.0001 (3.09) 178.2827 (3.13) 2,987.0686 (2.90) 176.7245 (3.14) 21.7145 (2.29) 1.4492 (3.45) 425;19445 5,609.0685 (0.32) 195122 29
test_fractions 1,207.9836 (21.80) 1,367.8852 (24.02) 26,541.0054 (25.76) 1,374.9814 (24.44) 203.0300 (21.41) 41.0364 (97.78) 200;3167 731.0555 (0.04) 100837 1
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------ benchmark 'Test Square Root': 4 tests ------------------------------------------------------------------------------
Name (time in ns) Min Mean Max Median StdDev IQR Outliers OPS (Mops/s) Rounds Iterations
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_floats 36.4220 (1.0) 37.7584 (1.0) 478.0888 (1.0) 37.3482 (1.0) 3.2950 (1.0) 0.3040 (1.0) 1706;36535 26.4841 (1.0) 198334 135
test_ints 44.3393 (1.22) 46.1888 (1.22) 617.3488 (1.29) 45.4863 (1.22) 5.5569 (1.69) 1.5235 (5.01) 748;6434 21.6503 (0.82) 199999 109
test_decimals 82.9459 (2.28) 153.9302 (4.08) 10,624.9936 (22.22) 166.0082 (4.44) 40.5108 (12.29) 41.9677 (138.06) 3525;384 6.4964 (0.25) 196735 1
test_fractions 224.1910 (6.16) 235.7727 (6.24) 2,827.3817 (5.91) 234.1417 (6.27) 15.2713 (4.63) 5.9538 (19.59) 1698;3803 4.2414 (0.16) 196733 21
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------ benchmark 'Test Subtraction': 4 tests ------------------------------------------------------------------------------
Name (time in ns) Min Mean Max Median StdDev IQR Outliers OPS (Mops/s) Rounds Iterations
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_ints 32.0720 (1.0) 33.0952 (1.0) 370.6116 (1.0) 32.8950 (1.0) 2.3966 (1.0) 0.2696 (39.78) 1085;13956 30.2159 (1.0) 199999 152
test_floats 33.6779 (1.05) 34.7292 (1.05) 438.3563 (1.18) 34.5343 (1.05) 3.0084 (1.26) 0.0068 (1.0) 779;64176 28.7943 (0.95) 198334 146
test_decimals 53.7501 (1.68) 55.1926 (1.67) 640.8297 (1.73) 54.9998 (1.67) 3.9756 (1.66) 0.4104 (60.55) 1092;18198 18.1184 (0.60) 181817 100
test_fractions 658.2995 (20.53) 687.7079 (20.78) 5,052.0990 (13.63) 687.4994 (20.90) 38.4347 (16.04) 16.6474 (>1000.0) 556;830 1.4541 (0.05) 59852 20
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------- benchmark 'Test Truncate': 4 tests --------------------------------------------------------------------------------
Name (time in ns) Min Mean Max Median StdDev IQR Outliers OPS (Mops/s) Rounds Iterations
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_floats 30.9244 (1.0) 31.9736 (1.0) 477.7231 (1.0) 31.7107 (1.0) 3.2904 (1.0) 0.0066 (1.0) 1031;93140 31.2758 (1.0) 198334 159
test_ints 40.9782 (1.33) 113.7337 (3.56) 24,500.0119 (51.28) 124.9718 (3.94) 75.8863 (23.06) 41.0364 (>1000.0) 220;220 8.7925 (0.28) 119403 1
test_fractions 97.0799 (3.14) 99.3647 (3.11) 952.9199 (1.99) 98.7499 (3.11) 7.1866 (2.18) 0.4197 (63.69) 657;13703 10.0639 (0.32) 100837 100
test_decimals 107.2898 (3.47) 108.8447 (3.40) 727.2948 (1.52) 108.1251 (3.41) 7.7458 (2.35) 0.4197 (63.69) 491;4759 9.1874 (0.29) 45978 200
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Legend:
Outliers: 1 Standard Deviation from Mean; 1.5 IQR (InterQuartile Range) from 1st Quartile and 3rd Quartile.
OPS: Operations Per Second, computed as 1 / Mean
import pytest
from decimal import Decimal, getcontext
from fractions import Fraction
from operator import add, sub, mul, truediv, eq, pow
from math import pi, sqrt, trunc, floor, ceil
getcontext().prec = 6
class TestInitialization:
@pytest.mark.benchmark(group="Test Initialization", disable_gc=True)
def test_ints(self, benchmark):
benchmark(int, 0.75)
@pytest.mark.benchmark(group="Test Initialization", disable_gc=True)
def test_floats(self, benchmark):
benchmark(float, 0.75)
@pytest.mark.benchmark(group="Test Initialization", disable_gc=True)
def test_decimals(self, benchmark):
benchmark(Decimal, 0.75)
@pytest.mark.benchmark(group="Test Initialization", disable_gc=True)
def test_fractions(self, benchmark):
benchmark(Fraction, 3, 4)
class TestFromString:
@pytest.mark.benchmark(group="Test From String", disable_gc=True)
def test_ints(self, benchmark):
benchmark(int, "1")
@pytest.mark.benchmark(group="Test From String", disable_gc=True)
def test_floats(self, benchmark):
benchmark(float, "0.75")
@pytest.mark.benchmark(group="Test From String", disable_gc=True)
def test_decimals(self, benchmark):
benchmark(Decimal, "0.75")
@pytest.mark.benchmark(group="Test From String", disable_gc=True)
def test_fractions(self, benchmark):
benchmark(Fraction, "0.75")
class TestAddition:
@pytest.mark.benchmark(group="Test Addition", disable_gc=True)
def test_ints(self, benchmark):
benchmark(add, 7, 9)
@pytest.mark.benchmark(group="Test Addition", disable_gc=True)
def test_floats(self, benchmark):
benchmark(add, 7.0, 9.0)
@pytest.mark.benchmark(group="Test Addition", disable_gc=True)
def test_decimals(self, benchmark):
benchmark(add, Decimal(7), Decimal(9))
@pytest.mark.benchmark(group="Test Addition", disable_gc=True)
def test_fractions(self, benchmark):
a = Fraction(3, 4)
b = Fraction(1, 3)
benchmark(add, a, b)
class TestSubtraction:
@pytest.mark.benchmark(group="Test Subtraction", disable_gc=True)
def test_ints(self, benchmark):
benchmark(sub, 7, 9)
@pytest.mark.benchmark(group="Test Subtraction", disable_gc=True)
def test_floats(self, benchmark):
benchmark(sub, 7.0, 9.0)
@pytest.mark.benchmark(group="Test Subtraction", disable_gc=True)
def test_decimals(self, benchmark):
benchmark(sub, Decimal(7), Decimal(9))
@pytest.mark.benchmark(group="Test Subtraction", disable_gc=True)
def test_fractions(self, benchmark):
a = Fraction(3, 4)
b = Fraction(1, 3)
benchmark(sub, a, b)
class TestMultiplication:
@pytest.mark.benchmark(group="Test Multiplication", disable_gc=True)
def test_ints(self, benchmark):
benchmark(mul, 7, 9)
@pytest.mark.benchmark(group="Test Multiplication", disable_gc=True)
def test_floats(self, benchmark):
benchmark(mul, 7.0, 9.0)
@pytest.mark.benchmark(group="Test Multiplication", disable_gc=True)
def test_decimals(self, benchmark):
benchmark(mul, Decimal(7), Decimal(9))
@pytest.mark.benchmark(group="Test Multiplication", disable_gc=True)
def test_fractions(self, benchmark):
a = Fraction(3, 4)
b = Fraction(1, 3)
benchmark(mul, a, b)
class TestDivision:
@pytest.mark.benchmark(group="Test Division", disable_gc=True)
def test_ints(self, benchmark):
benchmark(truediv, 7, 9)
@pytest.mark.benchmark(group="Test Division", disable_gc=True)
def test_floats(self, benchmark):
benchmark(truediv, 7.0, 9.0)
@pytest.mark.benchmark(group="Test Division", disable_gc=True)
def test_decimals(self, benchmark):
benchmark(truediv, Decimal(7), Decimal(9))
@pytest.mark.benchmark(group="Test Division", disable_gc=True)
def test_fractions(self, benchmark):
a = Fraction(3, 4)
b = Fraction(1, 3)
benchmark(truediv, a, b)
class TestSquareRoot:
@pytest.mark.benchmark(group="Test Square Root", disable_gc=True)
def test_ints(self, benchmark):
benchmark(sqrt, 2)
@pytest.mark.benchmark(group="Test Square Root", disable_gc=True)
def test_floats(self, benchmark):
benchmark(sqrt, 2.0)
@pytest.mark.benchmark(group="Test Square Root", disable_gc=True)
def test_decimals(self, benchmark):
benchmark(sqrt, Decimal(2))
@pytest.mark.benchmark(group="Test Square Root", disable_gc=True)
def test_fractions(self, benchmark):
a = Fraction(3, 4)
benchmark(sqrt, a)
class TestEquality:
@pytest.mark.benchmark(group="Test Equality", disable_gc=True)
def test_ints(self, benchmark):
benchmark(eq, 17, 1)
@pytest.mark.benchmark(group="Test Equality", disable_gc=True)
def test_floats(self, benchmark):
benchmark(eq, 17.4, 1.01)
@pytest.mark.benchmark(group="Test Equality", disable_gc=True)
def test_decimals(self, benchmark):
benchmark(eq, Decimal(17.4), Decimal(1.01))
@pytest.mark.benchmark(group="Test Equality", disable_gc=True)
def test_fractions(self, benchmark):
a = Fraction(3, 4)
b = Fraction(1, 3)
benchmark(eq, a, b)
class TestExponential:
@pytest.mark.benchmark(group="Test Exponential", disable_gc=True)
def test_ints(self, benchmark):
benchmark(pow, 4, 2)
@pytest.mark.benchmark(group="Test Exponential", disable_gc=True)
def test_floats(self, benchmark):
benchmark(pow, 0.25, 2)
@pytest.mark.benchmark(group="Test Exponential", disable_gc=True)
def test_decimals(self, benchmark):
benchmark(pow, Decimal(0.25), Decimal(2))
@pytest.mark.benchmark(group="Test Exponential", disable_gc=True)
def test_fractions(self, benchmark):
a = Fraction(1,4)
benchmark(pow, a, 2)
class TestTruncate:
@pytest.mark.benchmark(group="Test Truncate", disable_gc=True)
def test_ints(self, benchmark):
benchmark(trunc, 2)
@pytest.mark.benchmark(group="Test Truncate", disable_gc=True)
def test_floats(self, benchmark):
benchmark(trunc, 2.3333333333333335)
@pytest.mark.benchmark(group="Test Truncate", disable_gc=True)
def test_decimals(self, benchmark):
benchmark(trunc, Decimal(2.3333333333333335))
@pytest.mark.benchmark(group="Test Truncate", disable_gc=True)
def test_fractions(self, benchmark):
a = Fraction(7,3)
benchmark(trunc, a)
class TestFloor:
@pytest.mark.benchmark(group="Test Floor", disable_gc=True)
def test_ints(self, benchmark):
benchmark(floor, 2)
@pytest.mark.benchmark(group="Test Floor", disable_gc=True)
def test_floats(self, benchmark):
benchmark(floor, 2.3333333333333335)
@pytest.mark.benchmark(group="Test Floor", disable_gc=True)
def test_decimals(self, benchmark):
benchmark(floor, Decimal(2.3333333333333335))
@pytest.mark.benchmark(group="Test Floor", disable_gc=True)
def test_fractions(self, benchmark):
a = Fraction(7,3)
benchmark(floor, a)
class TestCeil:
@pytest.mark.benchmark(group="Test Ceil", disable_gc=True)
def test_ints(self, benchmark):
benchmark(ceil, 2)
@pytest.mark.benchmark(group="Test Ceil", disable_gc=True)
def test_floats(self, benchmark):
benchmark(ceil, 2.3333333333333335)
@pytest.mark.benchmark(group="Test Ceil", disable_gc=True)
def test_decimals(self, benchmark):
benchmark(ceil, Decimal(2.3333333333333335))
@pytest.mark.benchmark(group="Test Ceil", disable_gc=True)
def test_fractions(self, benchmark):
a = Fraction(7,3)
benchmark(ceil, a)
class TestRound:
@pytest.mark.benchmark(group="Test Round", disable_gc=True)
def test_ints(self, benchmark):
benchmark(round, 2, 2)
@pytest.mark.benchmark(group="Test Round", disable_gc=True)
def test_floats(self, benchmark):
benchmark(round, 2.3333333333333335, 2)
@pytest.mark.benchmark(group="Test Round", disable_gc=True)
def test_decimals(self, benchmark):
benchmark(round, Decimal(2.3333333333333335), 2)
@pytest.mark.benchmark(group="Test Round", disable_gc=True)
def test_fractions(self, benchmark):
a = Fraction(7,3)
benchmark(round, a, 2)

Python Numeric Types Performance Benchmarks

This document is a collection of performance benchmarks that compare the performance of mathmatical operations on the Python numeric types int, float, Decimal, and Fraction. Benchmarks were done using the Python package pytest-benchmark.

The benchmark was run on July 5th, 2024.

See [TODO] for the rationale of why I did this. The benchmarks were run on a machine with the following specs.

Metric Value
Make Apple
Model Mac Studio
Build Year 2022
Chip M1 Max
RAM 64 GB
OS Sonoma 14.5

Python Specs

Metric Value
sys.version 3.11.6 (main, Oct 2 2023, 13:45:54) [Clang 16.0.6 ]
sys.implementation.name cpython
sys.platform darwin
os.name posix

Benchmark Configurations The default pytest-benchmark settings were used.

Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
<?xml version='1.0' encoding='utf-8'?>
<svg xmlns="http://www.w3.org/2000/svg" id="chart-d8c8fac9-8011-4af6-a4d0-8697947030a9" class="pygal-chart" viewBox="0 0 800 600"><!--Generated with pygal 3.0.4 (etree) ©Kozea 2012-2016 on 2024-07-05--><!--http://pygal.org--><!--http://github.com/Kozea/pygal--><defs><style type="text/css">#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9{-webkit-user-select:none;-webkit-font-smoothing:antialiased;font-family:Consolas,"Deja Vu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .title{font-family:Consolas,"Deja Vu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace;font-size:16px}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .legends .legend text{font-family:Consolas,"Deja Vu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace;font-size:14px}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .axis text{font-family:Consolas,"Deja Vu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace;font-size:10px}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .axis text.major{font-family:Consolas,"Deja Vu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace;font-size:10px}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .text-overlay text.value{font-family:Consolas,"Deja Vu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace;font-size:16px}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .text-overlay text.label{font-family:Consolas,"Deja Vu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace;font-size:10px}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .tooltip{font-family:Consolas,"Deja Vu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace;font-size:14px}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 text.no_data{font-family:Consolas,"Deja Vu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace;font-size:64px}
#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9{background-color:rgba(249,249,249,1)}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 path,#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 line,#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 rect,#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 circle{-webkit-transition:150ms;-moz-transition:150ms;transition:150ms}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .graph &gt; .background{fill:rgba(249,249,249,1)}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .plot &gt; .background{fill:rgba(255,255,255,1)}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .graph{fill:rgba(0,0,0,.87)}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 text.no_data{fill:rgba(0,0,0,1)}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .title{fill:rgba(0,0,0,1)}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .legends .legend text{fill:rgba(0,0,0,.87)}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .legends .legend:hover text{fill:rgba(0,0,0,1)}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .axis .line{stroke:rgba(0,0,0,1)}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .axis .guide.line{stroke:rgba(0,0,0,.54)}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .axis .major.line{stroke:rgba(0,0,0,.87)}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .axis text.major{fill:rgba(0,0,0,1)}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .axis.y .guides:hover .guide.line,#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .line-graph .axis.x .guides:hover .guide.line,#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .stackedline-graph .axis.x .guides:hover .guide.line,#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .xy-graph .axis.x .guides:hover .guide.line{stroke:rgba(0,0,0,1)}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .axis .guides:hover text{fill:rgba(0,0,0,1)}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .reactive{fill-opacity:.7;stroke-opacity:.8;stroke-width:1}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .ci{stroke:rgba(0,0,0,.87)}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .reactive.active,#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .active .reactive{fill-opacity:.8;stroke-opacity:.9;stroke-width:4}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .ci .reactive.active{stroke-width:1.5}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .series text{fill:rgba(0,0,0,1)}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .tooltip rect{fill:rgba(255,255,255,1);stroke:rgba(0,0,0,1);-webkit-transition:opacity 150ms;-moz-transition:opacity 150ms;transition:opacity 150ms}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .tooltip .label{fill:rgba(0,0,0,.87)}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .tooltip .label{fill:rgba(0,0,0,.87)}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .tooltip .legend{font-size:.8em;fill:rgba(0,0,0,.54)}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .tooltip .x_label{font-size:.6em;fill:rgba(0,0,0,1)}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .tooltip .xlink{font-size:.5em;text-decoration:underline}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .tooltip .value{font-size:1.5em}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .bound{font-size:.5em}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .max-value{font-size:.75em;fill:rgba(0,0,0,.54)}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .map-element{fill:rgba(255,255,255,1);stroke:rgba(0,0,0,.54) !important}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .map-element .reactive{fill-opacity:inherit;stroke-opacity:inherit}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .color-0,#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .color-0 a:visited{stroke:#3F51B5;fill:#3F51B5}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .color-1,#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .color-1 a:visited{stroke:#3F51B5;fill:#3F51B5}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .color-2,#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .color-2 a:visited{stroke:#3F51B5;fill:#3F51B5}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .color-3,#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .color-3 a:visited{stroke:#3F51B5;fill:#3F51B5}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .text-overlay .color-0 text{fill:black}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .text-overlay .color-1 text{fill:black}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .text-overlay .color-2 text{fill:black}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .text-overlay .color-3 text{fill:black}
#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 text.no_data{text-anchor:middle}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .guide.line{fill:none}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .centered{text-anchor:middle}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .title{text-anchor:middle}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .legends .legend text{fill-opacity:1}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .axis.x text{text-anchor:middle}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .axis.x:not(.web) text[transform]{text-anchor:start}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .axis.x:not(.web) text[transform].backwards{text-anchor:end}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .axis.y text{text-anchor:end}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .axis.y text[transform].backwards{text-anchor:start}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .axis.y2 text{text-anchor:start}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .axis.y2 text[transform].backwards{text-anchor:end}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .axis .guide.line{stroke-dasharray:4,4;stroke:black}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .axis .major.guide.line{stroke-dasharray:6,6;stroke:black}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .horizontal .axis.y .guide.line,#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .horizontal .axis.y2 .guide.line,#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .vertical .axis.x .guide.line{opacity:0}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .horizontal .axis.always_show .guide.line,#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .vertical .axis.always_show .guide.line{opacity:1 !important}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .axis.y .guides:hover .guide.line,#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .axis.y2 .guides:hover .guide.line,#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .axis.x .guides:hover .guide.line{opacity:1}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .axis .guides:hover text{opacity:1}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .nofill{fill:none}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .subtle-fill{fill-opacity:.2}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .dot{stroke-width:1px;fill-opacity:1;stroke-opacity:1}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .dot.active{stroke-width:5px}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .dot.negative{fill:transparent}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 text,#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 tspan{stroke:none !important}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .series text.active{opacity:1}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .tooltip rect{fill-opacity:.95;stroke-width:.5}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .tooltip text{fill-opacity:1}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .showable{visibility:hidden}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .showable.shown{visibility:visible}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .gauge-background{fill:rgba(229,229,229,1);stroke:none}#chart-d8c8fac9-8011-4af6-a4d0-8697947030a9 .bg-lines{stroke:rgba(249,249,249,1);stroke-width:2px}
.tooltip .value{font-size:1em !important}.axis text{font-size:9px !important}</style><script type="text/javascript">window.pygal = window.pygal || {};window.pygal.config = window.pygal.config || {};window.pygal.config['d8c8fac9-8011-4af6-a4d0-8697947030a9'] = {"allow_interruptions": false, "box_mode": "tukey", "classes": ["pygal-chart"], "css": ["file://style.css", "file://graph.css", "inline:\n .tooltip .value {\n font-size: 1em !important;\n }\n .axis text {\n font-size: 9px !important;\n }\n "], "defs": [], "disable_xml_declaration": false, "dots_size": 2.5, "dynamic_print_values": false, "explicit_size": false, "fill": false, "force_uri_protocol": "https", "formatter": null, "half_pie": false, "height": 600, "include_x_axis": false, "inner_radius": 0, "interpolate": null, "interpolation_parameters": {}, "interpolation_precision": 250, "inverse_y_axis": false, "js": ["file:///Users/samuelholloway/Documents/Code/agents-playground/.venv/lib/python3.11/site-packages/pygaljs/static/2.0.x/pygal-tooltips.js"], "legend_at_bottom": false, "legend_at_bottom_columns": null, "legend_box_size": 12, "logarithmic": false, "margin": 20, "margin_bottom": null, "margin_left": null, "margin_right": null, "margin_top": null, "max_scale": 20, "min_scale": 20, "missing_value_fill_truncation": "x", "no_data_text": "No data", "no_prefix": false, "order_min": null, "pretty_print": false, "print_labels": false, "print_values": false, "print_values_position": "center", "print_zeroes": true, "range": [30, 163], "rounded_bars": null, "secondary_range": null, "show_dots": true, "show_legend": false, "show_minor_x_labels": true, "show_minor_y_labels": true, "show_only_major_dots": false, "show_x_guides": false, "show_x_labels": true, "show_y_guides": true, "show_y_labels": true, "spacing": 10, "stack_from_top": false, "strict": false, "stroke": true, "stroke_style": null, "style": {"background": "rgba(249, 249, 249, 1)", "ci_colors": [], "colors": ["#3F51B5", "#3F51B5", "#3F51B5", "#3F51B5"], "dot_opacity": "1", "font_family": "Consolas, \"Deja Vu Sans Mono\", \"Bitstream Vera Sans Mono\", \"Courier New\", monospace", "foreground": "rgba(0, 0, 0, .87)", "foreground_strong": "rgba(0, 0, 0, 1)", "foreground_subtle": "rgba(0, 0, 0, .54)", "guide_stroke_color": "black", "guide_stroke_dasharray": "4,4", "label_font_family": "Consolas, \"Deja Vu Sans Mono\", \"Bitstream Vera Sans Mono\", \"Courier New\", monospace", "label_font_size": 10, "legend_font_family": "Consolas, \"Deja Vu Sans Mono\", \"Bitstream Vera Sans Mono\", \"Courier New\", monospace", "legend_font_size": 14, "major_guide_stroke_color": "black", "major_guide_stroke_dasharray": "6,6", "major_label_font_family": "Consolas, \"Deja Vu Sans Mono\", \"Bitstream Vera Sans Mono\", \"Courier New\", monospace", "major_label_font_size": 10, "no_data_font_family": "Consolas, \"Deja Vu Sans Mono\", \"Bitstream Vera Sans Mono\", \"Courier New\", monospace", "no_data_font_size": 64, "opacity": ".7", "opacity_hover": ".8", "plot_background": "rgba(255, 255, 255, 1)", "stroke_opacity": ".8", "stroke_opacity_hover": ".9", "stroke_width": "1", "stroke_width_hover": "4", "title_font_family": "Consolas, \"Deja Vu Sans Mono\", \"Bitstream Vera Sans Mono\", \"Courier New\", monospace", "title_font_size": 16, "tooltip_font_family": "Consolas, \"Deja Vu Sans Mono\", \"Bitstream Vera Sans Mono\", \"Courier New\", monospace", "tooltip_font_size": 14, "transition": "150ms", "value_background": "rgba(229, 229, 229, 1)", "value_colors": [], "value_font_family": "Consolas, \"Deja Vu Sans Mono\", \"Bitstream Vera Sans Mono\", \"Courier New\", monospace", "value_font_size": 16, "value_label_font_family": "Consolas, \"Deja Vu Sans Mono\", \"Bitstream Vera Sans Mono\", \"Courier New\", monospace", "value_label_font_size": 10}, "title": "Speed in Nanoseconds (ns) of Test Floor", "tooltip_border_radius": 0, "tooltip_fancy_mode": true, "truncate_label": 50, "truncate_legend": null, "width": 800, "x_label_rotation": 270, "x_labels": ["test_floats", "test_ints", "test_decimals", "test_fractions"], "x_labels_major": null, "x_labels_major_count": null, "x_labels_major_every": null, "x_title": "Trial", "xrange": null, "y_label_rotation": 0, "y_labels": null, "y_labels_major": null, "y_labels_major_count": null, "y_labels_major_every": null, "y_title": "Duration", "zero": 30, "legends": ["benchmarks/spatial/numerical_test.py::TestFloor::test_floats - 199999 rounds", "benchmarks/spatial/numerical_test.py::TestFloor::test_ints - 177780 rounds", "benchmarks/spatial/numerical_test.py::TestFloor::test_decimals - 46064 rounds", "benchmarks/spatial/numerical_test.py::TestFloor::test_fractions - 195122 rounds"]}</script><script type="text/javascript">(function() {
var $, get_translation, init, init_svg, matches, padding, r_translation, sibl, svg_ns, tooltip_timeout, xlink_ns;
svg_ns = 'http://www.w3.org/2000/svg';
xlink_ns = 'http://www.w3.org/1999/xlink';
$ = function(sel, ctx) {
if (ctx == null) {
ctx = null;
}
ctx = ctx || document;
return Array.prototype.slice.call(ctx.querySelectorAll(sel), 0).filter(function(e) {
return e !== ctx;
});
};
matches = function(el, selector) {
return (el.matches || el.matchesSelector || el.msMatchesSelector || el.mozMatchesSelector || el.webkitMatchesSelector || el.oMatchesSelector).call(el, selector);
};
sibl = function(el, match) {
if (match == null) {
match = null;
}
return Array.prototype.filter.call(el.parentElement.children, function(child) {
return child !== el &amp;&amp; (!match || matches(child, match));
});
};
Array.prototype.one = function() {
return this.length &gt; 0 &amp;&amp; this[0] || {};
};
padding = 5;
tooltip_timeout = null;
r_translation = /translate\((\d+)[ ,]+(\d+)\)/;
get_translation = function(el) {
return (r_translation.exec(el.getAttribute('transform')) || []).slice(1).map(function(x) {
return +x;
});
};
init = function(ctx) {
var bbox, box, config, el, graph, inner_svg, num, parent, tooltip, tooltip_el, tt, uid, untooltip, xconvert, yconvert, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _ref3;
if ($('svg', ctx).length) {
inner_svg = $('svg', ctx).one();
parent = inner_svg.parentElement;
box = inner_svg.viewBox.baseVal;
bbox = parent.getBBox();
xconvert = function(x) {
return ((x - box.x) / box.width) * bbox.width;
};
yconvert = function(y) {
return ((y - box.y) / box.height) * bbox.height;
};
} else {
xconvert = yconvert = function(x) {
return x;
};
}
if (((_ref = window.pygal) != null ? _ref.config : void 0) != null) {
if (window.pygal.config.no_prefix != null) {
config = window.pygal.config;
} else {
uid = ctx.id.replace('chart-', '');
config = window.pygal.config[uid];
}
} else {
config = window.config;
}
tooltip_el = null;
graph = $('.graph').one();
tt = $('.tooltip', ctx).one();
_ref1 = $('.reactive', ctx);
for (_i = 0, _len = _ref1.length; _i &lt; _len; _i++) {
el = _ref1[_i];
el.addEventListener('mouseenter', (function(el) {
return function() {
return el.classList.add('active');
};
})(el));
el.addEventListener('mouseleave', (function(el) {
return function() {
return el.classList.remove('active');
};
})(el));
}
_ref2 = $('.activate-serie', ctx);
for (_j = 0, _len1 = _ref2.length; _j &lt; _len1; _j++) {
el = _ref2[_j];
num = el.id.replace('activate-serie-', '');
el.addEventListener('mouseenter', (function(num) {
return function() {
var re, _k, _len2, _ref3, _results;
_ref3 = $('.serie-' + num + ' .reactive', ctx);
_results = [];
for (_k = 0, _len2 = _ref3.length; _k &lt; _len2; _k++) {
re = _ref3[_k];
_results.push(re.classList.add('active'));
}
return _results;
};
})(num));
el.addEventListener('mouseleave', (function(num) {
return function() {
var re, _k, _len2, _ref3, _results;
_ref3 = $('.serie-' + num + ' .reactive', ctx);
_results = [];
for (_k = 0, _len2 = _ref3.length; _k &lt; _len2; _k++) {
re = _ref3[_k];
_results.push(re.classList.remove('active'));
}
return _results;
};
})(num));
el.addEventListener('click', (function(el, num) {
return function() {
var ov, re, rect, show, _k, _l, _len2, _len3, _ref3, _ref4, _results;
rect = $('rect', el).one();
show = rect.style.fill !== '';
rect.style.fill = show ? '' : 'transparent';
_ref3 = $('.serie-' + num + ' .reactive', ctx);
for (_k = 0, _len2 = _ref3.length; _k &lt; _len2; _k++) {
re = _ref3[_k];
re.style.display = show ? '' : 'none';
}
_ref4 = $('.text-overlay .serie-' + num, ctx);
_results = [];
for (_l = 0, _len3 = _ref4.length; _l &lt; _len3; _l++) {
ov = _ref4[_l];
_results.push(ov.style.display = show ? '' : 'none');
}
return _results;
};
})(el, num));
}
_ref3 = $('.tooltip-trigger', ctx);
for (_k = 0, _len2 = _ref3.length; _k &lt; _len2; _k++) {
el = _ref3[_k];
el.addEventListener('mouseenter', (function(el) {
return function() {
return tooltip_el = tooltip(el);
};
})(el));
}
tt.addEventListener('mouseenter', function() {
return tooltip_el != null ? tooltip_el.classList.add('active') : void 0;
});
tt.addEventListener('mouseleave', function() {
return tooltip_el != null ? tooltip_el.classList.remove('active') : void 0;
});
ctx.addEventListener('mouseleave', function() {
if (tooltip_timeout) {
clearTimeout(tooltip_timeout);
}
return untooltip(0);
});
graph.addEventListener('mousemove', function(el) {
if (tooltip_timeout) {
return;
}
if (!matches(el.target, '.background')) {
return;
}
return untooltip(1000);
});
tooltip = function(el) {
var a, baseline, cls, current_x, current_y, dy, h, i, key, keys, label, legend, name, plot_x, plot_y, rect, serie_index, subval, text, text_group, texts, traversal, value, w, x, x_elt, x_label, xlink, y, y_elt, _l, _len3, _len4, _len5, _m, _n, _ref4, _ref5, _ref6, _ref7, _ref8;
clearTimeout(tooltip_timeout);
tooltip_timeout = null;
tt.style.opacity = 1;
tt.style.display = '';
text_group = $('g.text', tt).one();
rect = $('rect', tt).one();
text_group.innerHTML = '';
label = sibl(el, '.label').one().textContent;
x_label = sibl(el, '.x_label').one().textContent;
value = sibl(el, '.value').one().textContent;
xlink = sibl(el, '.xlink').one().textContent;
serie_index = null;
parent = el;
traversal = [];
while (parent) {
traversal.push(parent);
if (parent.classList.contains('series')) {
break;
}
parent = parent.parentElement;
}
if (parent) {
_ref4 = parent.classList;
for (_l = 0, _len3 = _ref4.length; _l &lt; _len3; _l++) {
cls = _ref4[_l];
if (cls.indexOf('serie-') === 0) {
serie_index = +cls.replace('serie-', '');
break;
}
}
}
legend = null;
if (serie_index !== null) {
legend = config.legends[serie_index];
}
dy = 0;
keys = [[label, 'label']];
_ref5 = value.split('\n');
for (i = _m = 0, _len4 = _ref5.length; _m &lt; _len4; i = ++_m) {
subval = _ref5[i];
keys.push([subval, 'value-' + i]);
}
if (config.tooltip_fancy_mode) {
keys.push([xlink, 'xlink']);
keys.unshift([x_label, 'x_label']);
keys.unshift([legend, 'legend']);
}
texts = {};
for (_n = 0, _len5 = keys.length; _n &lt; _len5; _n++) {
_ref6 = keys[_n], key = _ref6[0], name = _ref6[1];
if (key) {
text = document.createElementNS(svg_ns, 'text');
text.textContent = key;
text.setAttribute('x', padding);
text.setAttribute('dy', dy);
text.classList.add(name.indexOf('value') === 0 ? 'value' : name);
if (name.indexOf('value') === 0 &amp;&amp; config.tooltip_fancy_mode) {
text.classList.add('color-' + serie_index);
}
if (name === 'xlink') {
a = document.createElementNS(svg_ns, 'a');
a.setAttributeNS(xlink_ns, 'href', key);
a.textContent = void 0;
a.appendChild(text);
text.textContent = 'Link &gt;';
text_group.appendChild(a);
} else {
text_group.appendChild(text);
}
dy += text.getBBox().height + padding / 2;
baseline = padding;
if (text.style.dominantBaseline !== void 0) {
text.style.dominantBaseline = 'text-before-edge';
} else {
baseline += text.getBBox().height * .8;
}
text.setAttribute('y', baseline);
texts[name] = text;
}
}
w = text_group.getBBox().width + 2 * padding;
h = text_group.getBBox().height + 2 * padding;
rect.setAttribute('width', w);
rect.setAttribute('height', h);
if (texts.value) {
texts.value.setAttribute('dx', (w - texts.value.getBBox().width) / 2 - padding);
}
if (texts.x_label) {
texts.x_label.setAttribute('dx', w - texts.x_label.getBBox().width - 2 * padding);
}
if (texts.xlink) {
texts.xlink.setAttribute('dx', w - texts.xlink.getBBox().width - 2 * padding);
}
x_elt = sibl(el, '.x').one();
y_elt = sibl(el, '.y').one();
x = parseInt(x_elt.textContent);
if (x_elt.classList.contains('centered')) {
x -= w / 2;
} else if (x_elt.classList.contains('left')) {
x -= w;
} else if (x_elt.classList.contains('auto')) {
x = xconvert(el.getBBox().x + el.getBBox().width / 2) - w / 2;
}
y = parseInt(y_elt.textContent);
if (y_elt.classList.contains('centered')) {
y -= h / 2;
} else if (y_elt.classList.contains('top')) {
y -= h;
} else if (y_elt.classList.contains('auto')) {
y = yconvert(el.getBBox().y + el.getBBox().height / 2) - h / 2;
}
_ref7 = get_translation(tt.parentElement), plot_x = _ref7[0], plot_y = _ref7[1];
if (x + w + plot_x &gt; config.width) {
x = config.width - w - plot_x;
}
if (y + h + plot_y &gt; config.height) {
y = config.height - h - plot_y;
}
if (x + plot_x &lt; 0) {
x = -plot_x;
}
if (y + plot_y &lt; 0) {
y = -plot_y;
}
_ref8 = get_translation(tt), current_x = _ref8[0], current_y = _ref8[1];
if (current_x === x &amp;&amp; current_y === y) {
return el;
}
tt.setAttribute('transform', "translate(" + x + " " + y + ")");
return el;
};
return untooltip = function(ms) {
return tooltip_timeout = setTimeout(function() {
tt.style.display = 'none';
tt.style.opacity = 0;
if (tooltip_el != null) {
tooltip_el.classList.remove('active');
}
return tooltip_timeout = null;
}, ms);
};
};
init_svg = function() {
var chart, charts, _i, _len, _results;
charts = $('.pygal-chart');
if (charts.length) {
_results = [];
for (_i = 0, _len = charts.length; _i &lt; _len; _i++) {
chart = charts[_i];
_results.push(init(chart));
}
return _results;
}
};
if (document.readyState !== 'loading') {
init_svg();
} else {
document.addEventListener('DOMContentLoaded', function() {
return init_svg();
});
}
window.pygal = window.pygal || {};
window.pygal.init = init;
window.pygal.init_svg = init_svg;
}).call(this);
</script></defs><title>Speed in Nanoseconds (ns) of Test Floor</title><g class="graph custombox-graph vertical"><rect x="0" y="0" width="800" height="600" class="background" /><g transform="translate(74, 46)" class="plot"><rect x="0" y="0" width="706.0" height="414.0" class="background" /><g class="axis y always_show"><path d="M0.000000 414.000000 h706.000000" class="line" /><g class="guides"><path d="M0.000000 400.052342 h706.000000" class="guide line" /><text x="-5" y="403.55234239444763" class="">32</text><title>32</title></g><g class="guides"><path d="M0.000000 376.107866 h706.000000" class="guide line" /><text x="-5" y="379.60786581839216" class="">40</text><title>40</title></g><g class="guides"><path d="M0.000000 352.163389 h706.000000" class="guide line" /><text x="-5" y="355.6633892423366" class="">48</text><title>48</title></g><g class="guides"><path d="M0.000000 328.218913 h706.000000" class="guide line" /><text x="-5" y="331.7189126662811" class="">56</text><title>56</title></g><g class="guides"><path d="M0.000000 304.274436 h706.000000" class="guide line" /><text x="-5" y="307.77443609022555" class="">64</text><title>64</title></g><g class="guides"><path d="M0.000000 280.329960 h706.000000" class="guide line" /><text x="-5" y="283.82995951417" class="">72</text><title>72</title></g><g class="guides"><path d="M0.000000 256.385483 h706.000000" class="guide line" /><text x="-5" y="259.88548293811454" class="">80</text><title>80</title></g><g class="guides"><path d="M0.000000 232.441006 h706.000000" class="guide line" /><text x="-5" y="235.941006362059" class="">88</text><title>88</title></g><g class="guides"><path d="M0.000000 208.496530 h706.000000" class="guide line" /><text x="-5" y="211.99652978600346" class="">96</text><title>96</title></g><g class="guides"><path d="M0.000000 184.552053 h706.000000" class="guide line" /><text x="-5" y="188.05205320994796" class="">104</text><title>104</title></g><g class="guides"><path d="M0.000000 160.607577 h706.000000" class="guide line" /><text x="-5" y="164.10757663389242" class="">112</text><title>112</title></g><g class="guides"><path d="M0.000000 136.663100 h706.000000" class="guide line" /><text x="-5" y="140.1631000578369" class="">120</text><title>120</title></g><g class="guides"><path d="M0.000000 112.718623 h706.000000" class="guide line" /><text x="-5" y="116.21862348178138" class="">128</text><title>128</title></g><g class="guides"><path d="M0.000000 88.774147 h706.000000" class="guide line" /><text x="-5" y="92.27414690572584" class="">136</text><title>136</title></g><g class="guides"><path d="M0.000000 64.829670 h706.000000" class="guide line" /><text x="-5" y="68.32967032967031" class="">144</text><title>144</title></g><g class="guides"><path d="M0.000000 40.885194 h706.000000" class="guide line" /><text x="-5" y="44.38519375361483" class="">152</text><title>152</title></g><g class="guides"><path d="M0.000000 16.940717 h706.000000" class="guide line" /><text x="-5" y="20.440717177559293" class="">160</text><title>160</title></g></g><g class="axis x"><path d="M0.000000 0.000000 v414.000000" class="line" /><g class="guides"><path d="M98.432692 0.000000 v414.000000" class="guide line" /><text x="98.43269230769229" y="429.0" class="backwards" transform="rotate(270 98.432692 429.000000)">test_floats</text></g><g class="guides"><path d="M268.144231 0.000000 v414.000000" class="guide line" /><text x="268.1442307692308" y="429.0" class="backwards" transform="rotate(270 268.144231 429.000000)">test_ints</text></g><g class="guides"><path d="M437.855769 0.000000 v414.000000" class="guide line" /><text x="437.8557692307692" y="429.0" class="backwards" transform="rotate(270 437.855769 429.000000)">test_decimals</text></g><g class="guides"><path d="M607.567308 0.000000 v414.000000" class="guide line" /><text x="607.5673076923076" y="429.0" class="backwards" transform="rotate(270 607.567308 429.000000)">test_fractions</text></g></g><g class="series serie-0 color-0"><g class="boxes"><g class="box"><path stroke-width="3" d="M61.096154 403.103305 L135.769231 403.103305" class="reactive tooltip-trigger" /><path stroke-width="3" d="M23.759615 398.306698 L173.105769 398.306698" class="reactive tooltip-trigger" /><path stroke-width="3" d="M61.096154 394.316413 L135.769231 394.316413" class="reactive tooltip-trigger" /><path stroke-width="2" d="M98.432692 403.103305 L98.432692 400.704443" class="reactive tooltip-trigger" /><path stroke-width="2" d="M98.432692 394.316413 L98.432692 398.286596" class="reactive tooltip-trigger" /><rect x="23.759615384615383" y="398.28659597188687" height="2.41784697289404" width="149.34615384615384" class="subtle-fill reactive tooltip-trigger" /><circle cx="98.4326923076923" cy="403.10330451419264" r="3" class="subtle-fill reactive tooltip-trigger" /><circle cx="98.4326923076923" cy="-348.3668850265984" r="3" class="subtle-fill reactive tooltip-trigger" /><desc class="value">Min: 30.9807
Q1-1.5IQR: 30.9807
Q1: 31.7821
Median: 32.5832
Q3: 32.5899
Q3+1.5IQR: 33.9164
Max: 282.0516</desc><desc class="x centered">98.4326923076923</desc><desc class="y centered">398.94349093237474</desc><desc class="x_label" /></g></g></g><g class="series serie-1 color-1"><g class="boxes"><g class="box"><path stroke-width="3" d="M230.807692 328.728098 L305.480769 328.728098" class="reactive tooltip-trigger" /><path stroke-width="3" d="M193.471154 327.470237 L342.817308 327.470237" class="reactive tooltip-trigger" /><path stroke-width="3" d="M230.807692 323.729755 L305.480769 323.729755" class="reactive tooltip-trigger" /><path stroke-width="2" d="M268.144231 328.728098 L268.144231 327.471979" class="reactive tooltip-trigger" /><path stroke-width="2" d="M268.144231 323.729755 L268.144231 326.243735" class="reactive tooltip-trigger" /><rect x="193.4711538461538" y="326.24373515870286" height="1.2282439264613458" width="149.34615384615384" class="subtle-fill reactive tooltip-trigger" /><circle cx="268.1442307692307" cy="331.2124609434799" r="3" class="subtle-fill reactive tooltip-trigger" /><circle cx="268.1442307692307" cy="-12098.72409062356" r="3" class="subtle-fill reactive tooltip-trigger" /><desc class="value">Min: 54.9998
Q1-1.5IQR: 55.8299
Q1: 56.2496
Median: 56.2501
Q3: 56.6599
Q3+1.5IQR: 57.4999
Max: 4207.9197</desc><desc class="x centered">268.1442307692307</desc><desc class="y centered">326.7287608454076</desc><desc class="x_label" /></g></g></g><g class="series serie-2 color-2"><g class="boxes"><g class="box"><path stroke-width="3" d="M400.519231 172.206267 L475.192308 172.206267" class="reactive tooltip-trigger" /><path stroke-width="3" d="M363.182692 169.707096 L512.528846 169.707096" class="reactive tooltip-trigger" /><path stroke-width="3" d="M400.519231 166.593802 L475.192308 166.593802" class="reactive tooltip-trigger" /><path stroke-width="2" d="M437.855769 172.206267 L437.855769 170.335155" class="reactive tooltip-trigger" /><path stroke-width="2" d="M437.855769 166.593802 L437.855769 169.078165" class="reactive tooltip-trigger" /><rect x="363.1826923076923" y="169.07816498569537" height="1.256990060910482" width="149.34615384615384" class="subtle-fill reactive tooltip-trigger" /><circle cx="437.8557692307692" cy="172.83432655371058" r="3" class="subtle-fill reactive tooltip-trigger" /><circle cx="437.8557692307692" cy="-1514.5036600543765" r="3" class="subtle-fill reactive tooltip-trigger" /><desc class="value">Min: 107.9150
Q1-1.5IQR: 108.1248
Q1: 108.7500
Median: 108.9598
Q3: 109.1699
Q3+1.5IQR: 110.0000
Max: 671.6652</desc><desc class="x centered">437.8557692307692</desc><desc class="y centered">169.58409695199947</desc><desc class="x_label" /></g></g></g><g class="series serie-3 color-3"><g class="boxes"><g class="box"><path stroke-width="3" d="M570.230769 85.078220 L644.903846 85.078220" class="reactive tooltip-trigger" /><path stroke-width="3" d="M532.894231 70.372087 L682.240385 70.372087" class="reactive tooltip-trigger" /><path stroke-width="3" d="M570.230769 8.052927 L644.903846 8.052927" class="reactive tooltip-trigger" /><path stroke-width="2" d="M607.567308 85.078220 L607.567308 73.984569" class="reactive tooltip-trigger" /><path stroke-width="2" d="M607.567308 8.052927 L607.567308 48.369252" class="reactive tooltip-trigger" /><rect x="532.8942307692307" y="48.36925212695701" height="25.61531659733174" width="149.34615384615384" class="subtle-fill reactive tooltip-trigger" /><circle cx="607.5673076923076" cy="85.07821954109676" r="3" class="subtle-fill reactive tooltip-trigger" /><circle cx="607.5673076923076" cy="-3979.143527276191" r="3" class="subtle-fill reactive tooltip-trigger" /><desc class="value">Min: 137.2348
Q1-1.5IQR: 137.2348
Q1: 140.9413
Median: 142.1482
Q3: 149.4995
Q3+1.5IQR: 162.9695
Max: 1495.1168</desc><desc class="x centered">607.5673076923076</desc><desc class="y centered">57.171410728856756</desc><desc class="x_label" /></g></g></g></g><g class="titles"><text x="400.0" y="26" class="title plot_title">Speed in Nanoseconds (ns) of Test Floor</text><text x="427.0" y="580.0" class="title">Trial</text><text x="0" y="279.0" class="title" transform="rotate(-90 0.000000 253.000000)">Duration</text></g><g transform="translate(74, 46)" class="plot overlay"><g class="series serie-0 color-0" /><g class="series serie-1 color-1" /><g class="series serie-2 color-2" /><g class="series serie-3 color-3" /></g><g transform="translate(74, 46)" class="plot text-overlay"><g class="series serie-0 color-0" /><g class="series serie-1 color-1" /><g class="series serie-2 color-2" /><g class="series serie-3 color-3" /></g><g transform="translate(74, 46)" class="plot tooltip-overlay"><g transform="translate(0 0)" style="opacity: 0" class="tooltip"><rect rx="0" ry="0" width="0" height="0" class="tooltip-box" /><g class="text" /></g></g></g></svg>
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment