GithubHelp home page GithubHelp logo

sort-race's Introduction

PHP Quicksort vs C Bubble Sort Throwdown

Copyright (c) 2019 Bart Massey

I borrowed a PHP implementation of Quicksort (quicksort.php) and wrote my own Bubble Sort in C (bubblesort.c) and comparable Rust (bubblesort.rs) so I could race 'em in response to a Reddit thread; (I also wrote a PHP Bubble Sort (bubblesort.php) just out of curiosity: it runs about 30ร— slower than PHP Quicksort.) Each implementation of Bubble Sort creates an array of the first n integers, shuffles it, and then sorts it back.

Turns out the breakeven on my box is about 5,000 elements: that is the size at which the PHP Quicksort, the C Bubble Sort compiled with GCC and the Rust Bubble Sort take about 0.012 seconds on my box. The output of the benchmark run shows compiler/interpreter versions and timing.

I timed both the simple and in-place PHP Quicksort: at this size they both run in about the same time. This suggests that PHP's startup overhead is a limiting factor: I wrote a Rust Quicksort transliterated directly from the PHP in-place quicksort, and raced them on 1M elements to get a fairer speed comparison. At this scale PHP is about 8ร— slower than Rust for Quicksort, which is actually pretty impressive.

C Bubble Sort compiled with Clang is about twice as fast: I suspect it has figured out that it doesn't have to do the whole sort since it only is printing the first element. Meh.

The standalone Rust Bubble Sort was a pain, since the Rust Standard Library apparently has no built-in random-number support. This was super-annoying: I currently require an extra "seed" argument to this program.

License

"MIT". Please see the file LICENSE in this distribution for license terms.

sort-race's People

Contributors

bartmassey avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.