gitkearney / php-node-bubblesort-test Goto Github PK
View Code? Open in Web Editor NEWCompare nodeJS and PHP speed using bubble sort algorithm
Compare nodeJS and PHP speed using bubble sort algorithm
I've set up a fork to demonstrate what I'm talking about. You can see it here:
https://github.com/ryantate13/php-node-bubblesort-test/
In my test runs PHP is consistently ~20x slower than Node. I set up a script to cycle through 100 test runs and take the min time of each set per platform.
If you clone my repo and run make test
you can see it in action. PHP is v7.2.18, Node is v10.14.2.
time elapsed (nanoseconds) for php is 133,391,141
time elapsed (nanoseconds) for node is 7,014,987
It might sound a bit like sorcery but if you will traverse array backwards you can achieve up to 3 times better performance. The only difference is to use this construction:
for ( var i = array.length; i--; ) {
(...)
}
There has been prolonged discussion about it on GitHub: https://stackoverflow.com/questions/5349425/whats-the-fastest-way-to-loop-through-an-array-in-javascript
and here you can find related test:
http://jsbench.github.io/#67b13d4e78cdd0d7a7346410d5becf12
I didn't check it in node though but in browser... :
https://jsbench.me/j0jw6pygqu/1
Also as you can see in tests you can gain performance on declaring the data type for array.
Wonder how much improvements can be gain in PHP and if running on node will make the difference.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.