GithubHelp home page GithubHelp logo

comparing-sorting-algs's Introduction

Comparing sorting algorithms

Prerequisites

You'll need to have Golang installed on your machine.


Sorting Algorithms


Results & specifications

Running all the benchmarks

go test --bench=. 

Running benchmarks only for a specific algorithm

go test --bench='(?i)<name>'

--bench takes in a regex and (?i) is used to indicate the case-insensitive modifier, so that you can simply type the name of the algorithm you'd want to see benchmarks for:

go test --bench='(?i)gnome'
go test --bench='(?i)heap'

Running benchmarks for specific algorithms

go test --bench='(?i)gnome|heap'

Warning regarding Stooge Sort

Because the Stooge Sort algorithm is extremely slow, I'd recommend you run the benchmarks for all the algorithms except this one. You can do so with the following command:

go test --bench='(?i)bubble|gnome|heap|count|native'

Sample results

After running

go test --bench='(?i)bubble|gnome|heap|count|native'

on my machine, I got the following results:

goos: linux
goarch: amd64
pkg: github.com/comparing_sorting_algorithms
BenchmarkBubbleSort/Permutations_of_1000_;_TOTAL_=_1000,_MAX_=_999_-8         	            336240	      3682 ns/op
BenchmarkBubbleSort/Permutations_of_10000_;_TOTAL_=_10000,_MAX_=_9999_-8      	             32919	     37025 ns/op
BenchmarkBubbleSort/ASC_Range_of_1000_elements_;_TOTAL_=_1000,_MAX_=_1000_-8  	            309852	      3634 ns/op
BenchmarkBubbleSort/ASC_Range_of_10000_elements_;_TOTAL_=_10000,_MAX_=_10000_-8         	   32521	     34923 ns/op
BenchmarkBubbleSort/DESC_Range_of_1000_elements_;_TOTAL_=_1000,_MAX_=_1000_-8           	  289390	      3524 ns/op
BenchmarkBubbleSort/DESC_Range_of_10000_elements_;_TOTAL_=_10000,_MAX_=_10000_-8        	   33108	     34188 ns/op
BenchmarkBubbleSort/Array_with_identical_elements:1_;_TOTAL_=_1000,_MAX_=_1_-8          	  325699	      3568 ns/op
BenchmarkBubbleSort/Array_with_identical_elements_1_;_TOTAL_=_10000,_MAX_=_1_-8         	   32696	     35299 ns/op

BenchmarkCountSort/Permutations_of_1000_;_TOTAL_=_1000,_MAX_=_999_-8                    	   44132	     28481 ns/op
BenchmarkCountSort/Permutations_of_10000_;_TOTAL_=_10000,_MAX_=_9999_-8                 	    8372	    169169 ns/op
BenchmarkCountSort/ASC_Range_of_1000_elements_;_TOTAL_=_1000,_MAX_=_1000_-8             	   39830	     31804 ns/op
BenchmarkCountSort/ASC_Range_of_10000_elements_;_TOTAL_=_10000,_MAX_=_10000_-8          	    7312	    176724 ns/op
BenchmarkCountSort/DESC_Range_of_1000_elements_;_TOTAL_=_1000,_MAX_=_1000_-8            	   39724	     31132 ns/op
BenchmarkCountSort/DESC_Range_of_10000_elements_;_TOTAL_=_10000,_MAX_=_10000_-8         	    6600	    178965 ns/op
BenchmarkCountSort/Array_with_identical_elements:1_;_TOTAL_=_1000,_MAX_=_1_-8           	   43245	     29294 ns/op
BenchmarkCountSort/Array_with_identical_elements_1_;_TOTAL_=_10000,_MAX_=_1_-8          	    7166	    164025 ns/op

BenchmarkHeapSort/Permutations_of_1000_;_TOTAL_=_1000,_MAX_=_999_-8                     	   17745	     66997 ns/op
BenchmarkHeapSort/Permutations_of_10000_;_TOTAL_=_10000,_MAX_=_9999_-8                  	    1368	    827720 ns/op
BenchmarkHeapSort/ASC_Range_of_1000_elements_;_TOTAL_=_1000,_MAX_=_1000_-8              	   16636	     67112 ns/op
BenchmarkHeapSort/ASC_Range_of_10000_elements_;_TOTAL_=_10000,_MAX_=_10000_-8           	    1390	    804317 ns/op
BenchmarkHeapSort/DESC_Range_of_1000_elements_;_TOTAL_=_1000,_MAX_=_1000_-8             	   18225	     65635 ns/op
BenchmarkHeapSort/DESC_Range_of_10000_elements_;_TOTAL_=_10000,_MAX_=_10000_-8          	    1398	    801088 ns/op
BenchmarkHeapSort/Array_with_identical_elements:1_;_TOTAL_=_1000,_MAX_=_1_-8            	  126187	      9371 ns/op
BenchmarkHeapSort/Array_with_identical_elements_1_;_TOTAL_=_10000,_MAX_=_1_-8           	   12574	     90953 ns/op

BenchmarkGnomeSort/Permutations_of_1000_;_TOTAL_=_1000,_MAX_=_999_-8                    	  315808	      3717 ns/op
BenchmarkGnomeSort/Permutations_of_10000_;_TOTAL_=_10000,_MAX_=_9999_-8                 	   31620	     36664 ns/op
BenchmarkGnomeSort/ASC_Range_of_1000_elements_;_TOTAL_=_1000,_MAX_=_1000_-8             	  320732	      3688 ns/op
BenchmarkGnomeSort/ASC_Range_of_10000_elements_;_TOTAL_=_10000,_MAX_=_10000_-8          	   29839	     38849 ns/op
BenchmarkGnomeSort/DESC_Range_of_1000_elements_;_TOTAL_=_1000,_MAX_=_1000_-8            	  296325	      4398 ns/op
BenchmarkGnomeSort/DESC_Range_of_10000_elements_;_TOTAL_=_10000,_MAX_=_10000_-8         	   29257	     37843 ns/op
BenchmarkGnomeSort/Array_with_identical_elements:1_;_TOTAL_=_1000,_MAX_=_1_-8           	  303585	      3667 ns/op
BenchmarkGnomeSort/Array_with_identical_elements_1_;_TOTAL_=_10000,_MAX_=_1_-8          	   32768	     36711 ns/op

BenchmarkNativeSort/Permutations_of_1000_;_TOTAL_=_1000,_MAX_=_999_-8                   	   30529	     35769 ns/op
BenchmarkNativeSort/Permutations_of_10000_;_TOTAL_=_10000,_MAX_=_9999_-8                	    2275	    580263 ns/op
BenchmarkNativeSort/ASC_Range_of_1000_elements_;_TOTAL_=_1000,_MAX_=_1000_-8            	   29115	     42563 ns/op
BenchmarkNativeSort/ASC_Range_of_10000_elements_;_TOTAL_=_10000,_MAX_=_10000_-8         	    2318	    533351 ns/op
BenchmarkNativeSort/DESC_Range_of_1000_elements_;_TOTAL_=_1000,_MAX_=_1000_-8           	   33187	     35630 ns/op
BenchmarkNativeSort/DESC_Range_of_10000_elements_;_TOTAL_=_10000,_MAX_=_10000_-8        	    2536	    474735 ns/op
BenchmarkNativeSort/Array_with_identical_elements:1_;_TOTAL_=_1000,_MAX_=_1_-8          	  124982	      9980 ns/op
BenchmarkNativeSort/Array_with_identical_elements_1_;_TOTAL_=_10000,_MAX_=_1_-8         	   12296	     94886 ns/op

PASS
ok  	github.com/comparing_sorting_algorithms	59.602s

Note: the second column indicates how many times the function was run within a second(by default). You can find more details here.

comparing-sorting-algs's People

Contributors

andrei0872 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.