I am creating a sorting comparison workbench using AWS to host sorting lambdas.
I have a bubble sort algorithm implemented in python (python3.8) and javascript (nodejs12.x) lambdas. Both have 512MB memory allocated.
When I run these against eachother with array lengths N of 1 to 5500 I get the following graph. N is on the x axis and time taken in MS on the y axis:
While I expect bubble sort to be slow, I didn't expect Python to be 100x slower compared with Javascript. The max milliseconds reached for JS is ~120, vs Python at ~11100.
Perhaps there is an AWS related explanation, or my implementation is very slow?
Update:
I switched the runtime over from CPython to PyPy and this has reduced the time by x100 for running bubble sort, the graphs are now much closer together, thus the time difference was due to the compiler:
question from:
https://stackoverflow.com/questions/66053519/why-is-a-python-lambda-wildly-slower-than-a-javascript-lambda-with-the-same-func 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…