Skip to content

Instantly share code, notes, and snippets.

@extemporalgenome
Last active December 11, 2015 16:38
Show Gist options
  • Save extemporalgenome/4629151 to your computer and use it in GitHub Desktop.
Save extemporalgenome/4629151 to your computer and use it in GitHub Desktop.
Odd behavior of golang's sort.Sort implementation.
package main
import (
"github.com/extemporalgenome/sortutil"
"os"
"sort"
)
func main() {
sortutil.Analyze(os.Stdout, true, sort.Sort)
}
#################################
### [ OK ] Ascending ###
#################################
(abcdefghijklmnopqrstuvwxyz).Len() [26]
(AbcdefghijklmNopqrstuvwxyz).Less( 0, 13) [true]
(AbcdefghijklmNopqrstuvwxyz).Swap( 0, 13) [NbcdefghijklmAopqrstuvwxyz]
(NbcdefghijklmaopqrstuvwxyZ).Less(25, 0) [false]
(NbcdefghijklmAopqrstuvwxyz).Less( 0, 13) [false]
(NBcdefghijklmaopqrstuvwxyz).Less( 1, 0) [true]
(NbCdefghijklmaopqrstuvwxyz).Less( 2, 0) [true]
(NbcDefghijklmaopqrstuvwxyz).Less( 3, 0) [true]
(NbcdEfghijklmaopqrstuvwxyz).Less( 4, 0) [true]
(NbcdeFghijklmaopqrstuvwxyz).Less( 5, 0) [true]
(NbcdefGhijklmaopqrstuvwxyz).Less( 6, 0) [true]
(NbcdefgHijklmaopqrstuvwxyz).Less( 7, 0) [true]
(NbcdefghIjklmaopqrstuvwxyz).Less( 8, 0) [true]
(NbcdefghiJklmaopqrstuvwxyz).Less( 9, 0) [true]
(NbcdefghijKlmaopqrstuvwxyz).Less(10, 0) [true]
(NbcdefghijkLmaopqrstuvwxyz).Less(11, 0) [true]
(NbcdefghijklMaopqrstuvwxyz).Less(12, 0) [true]
(NbcdefghijklmAopqrstuvwxyz).Less(13, 0) [true]
(NbcdefghijklmaOpqrstuvwxyz).Less(14, 0) [false]
(NbcdefghijklmaOpqrstuvwxyz).Less( 0, 14) [true]
(NbcdefghijklmaopqrstuvwxyZ).Less( 0, 25) [true]
(NbcdefghijklmaOpqrstuvwxyz).Less(14, 0) [false]
(NbcdefghijklmaOpqrstuvwxyz).Less( 0, 14) [true]
(NbcdefghijklmaopqrstuvwxYz).Less( 0, 24) [true]
(NbcdefghijklmaOpqrstuvwxyz).Less(14, 0) [false]
(NbcdefghijklmaOpqrstuvwxyz).Less( 0, 14) [true]
(NbcdefghijklmaopqrstuvwXyz).Less( 0, 23) [true]
(NbcdefghijklmaOpqrstuvwxyz).Less(14, 0) [false]
(NbcdefghijklmaOpqrstuvwxyz).Less( 0, 14) [true]
(NbcdefghijklmaopqrstuvWxyz).Less( 0, 22) [true]
(NbcdefghijklmaOpqrstuvwxyz).Less(14, 0) [false]
(NbcdefghijklmaOpqrstuvwxyz).Less( 0, 14) [true]
(NbcdefghijklmaopqrstuVwxyz).Less( 0, 21) [true]
(NbcdefghijklmaOpqrstuvwxyz).Less(14, 0) [false]
(NbcdefghijklmaOpqrstuvwxyz).Less( 0, 14) [true]
(NbcdefghijklmaopqrstUvwxyz).Less( 0, 20) [true]
(NbcdefghijklmaOpqrstuvwxyz).Less(14, 0) [false]
(NbcdefghijklmaOpqrstuvwxyz).Less( 0, 14) [true]
(NbcdefghijklmaopqrsTuvwxyz).Less( 0, 19) [true]
(NbcdefghijklmaOpqrstuvwxyz).Less(14, 0) [false]
(NbcdefghijklmaOpqrstuvwxyz).Less( 0, 14) [true]
(NbcdefghijklmaopqrStuvwxyz).Less( 0, 18) [true]
(NbcdefghijklmaOpqrstuvwxyz).Less(14, 0) [false]
(NbcdefghijklmaOpqrstuvwxyz).Less( 0, 14) [true]
(NbcdefghijklmaopqRstuvwxyz).Less( 0, 17) [true]
(NbcdefghijklmaOpqrstuvwxyz).Less(14, 0) [false]
(NbcdefghijklmaOpqrstuvwxyz).Less( 0, 14) [true]
(NbcdefghijklmaopQrstuvwxyz).Less( 0, 16) [true]
(NbcdefghijklmaOpqrstuvwxyz).Less(14, 0) [false]
(NbcdefghijklmaOpqrstuvwxyz).Less( 0, 14) [true]
(NbcdefghijklmaoPqrstuvwxyz).Less( 0, 15) [true]
(NbcdefghijklmaOpqrstuvwxyz).Less(14, 0) [false]
(NbcdefghijklmaOpqrstuvwxyz).Less( 0, 14) [true]
(NbcdefghijklmaOpqrstuvwxyz).Less( 0, 14) [true]
(NbcdefghijklmAopqrstuvwxyz).Swap( 0, 13) [AbcdefghijklmNopqrstuvwxyz]
(abcdefghijklmnOpqrstUvwxyz).Less(14, 20) [true]
(abcdefghijklmnOpqrstUvwxyz).Swap(14, 20) [abcdefghijklmnUpqrstOvwxyz]
(abcdefghijklmnUpqrstovwxyZ).Less(25, 14) [false]
(abcdefghijklmnUpqrstOvwxyz).Less(14, 20) [false]
(abcdefghijklmnUPqrstovwxyz).Less(15, 14) [true]
(abcdefghijklmnUpQrstovwxyz).Less(16, 14) [true]
(abcdefghijklmnUpqRstovwxyz).Less(17, 14) [true]
(abcdefghijklmnUpqrStovwxyz).Less(18, 14) [true]
(abcdefghijklmnUpqrsTovwxyz).Less(19, 14) [true]
(abcdefghijklmnUpqrstOvwxyz).Less(20, 14) [true]
(abcdefghijklmnUpqrstoVwxyz).Less(21, 14) [false]
(abcdefghijklmnUpqrstoVwxyz).Less(14, 21) [true]
(abcdefghijklmnUpqrstovwxyZ).Less(14, 25) [true]
(abcdefghijklmnUpqrstoVwxyz).Less(21, 14) [false]
(abcdefghijklmnUpqrstoVwxyz).Less(14, 21) [true]
(abcdefghijklmnUpqrstovwxYz).Less(14, 24) [true]
(abcdefghijklmnUpqrstoVwxyz).Less(21, 14) [false]
(abcdefghijklmnUpqrstoVwxyz).Less(14, 21) [true]
(abcdefghijklmnUpqrstovwXyz).Less(14, 23) [true]
(abcdefghijklmnUpqrstoVwxyz).Less(21, 14) [false]
(abcdefghijklmnUpqrstoVwxyz).Less(14, 21) [true]
(abcdefghijklmnUpqrstovWxyz).Less(14, 22) [true]
(abcdefghijklmnUpqrstoVwxyz).Less(21, 14) [false]
(abcdefghijklmnUpqrstoVwxyz).Less(14, 21) [true]
(abcdefghijklmnUpqrstoVwxyz).Less(14, 21) [true]
(abcdefghijklmnUpqrstOvwxyz).Swap(14, 20) [abcdefghijklmnOpqrstUvwxyz]
(abcdefghijklmnopqrstuVWxyz).Less(22, 21) [false]
(abcdefghijklmnopqrstuvWXyz).Less(23, 22) [false]
(abcdefghijklmnopqrstuvwXYz).Less(24, 23) [false]
(abcdefghijklmnopqrstuvwxYZ).Less(25, 24) [false]
(abcdefghijklmnOPqrstuvwxyz).Less(15, 14) [false]
(abcdefghijklmnoPQrstuvwxyz).Less(16, 15) [false]
(abcdefghijklmnopQRstuvwxyz).Less(17, 16) [false]
(abcdefghijklmnopqRStuvwxyz).Less(18, 17) [false]
(abcdefghijklmnopqrSTuvwxyz).Less(19, 18) [false]
(AbcdefGhijklmnopqrstuvwxyz).Less( 0, 6) [true]
(AbcdefGhijklmnopqrstuvwxyz).Swap( 0, 6) [GbcdefAhijklmnopqrstuvwxyz]
(GbcdefahijklMnopqrstuvwxyz).Less(12, 0) [false]
(GbcdefAhijklmnopqrstuvwxyz).Less( 0, 6) [false]
(GBcdefahijklmnopqrstuvwxyz).Less( 1, 0) [true]
(GbCdefahijklmnopqrstuvwxyz).Less( 2, 0) [true]
(GbcDefahijklmnopqrstuvwxyz).Less( 3, 0) [true]
(GbcdEfahijklmnopqrstuvwxyz).Less( 4, 0) [true]
(GbcdeFahijklmnopqrstuvwxyz).Less( 5, 0) [true]
(GbcdefAhijklmnopqrstuvwxyz).Less( 6, 0) [true]
(GbcdefaHijklmnopqrstuvwxyz).Less( 7, 0) [false]
(GbcdefaHijklmnopqrstuvwxyz).Less( 0, 7) [true]
(GbcdefahijklMnopqrstuvwxyz).Less( 0, 12) [true]
(GbcdefaHijklmnopqrstuvwxyz).Less( 7, 0) [false]
(GbcdefaHijklmnopqrstuvwxyz).Less( 0, 7) [true]
(GbcdefahijkLmnopqrstuvwxyz).Less( 0, 11) [true]
(GbcdefaHijklmnopqrstuvwxyz).Less( 7, 0) [false]
(GbcdefaHijklmnopqrstuvwxyz).Less( 0, 7) [true]
(GbcdefahijKlmnopqrstuvwxyz).Less( 0, 10) [true]
(GbcdefaHijklmnopqrstuvwxyz).Less( 7, 0) [false]
(GbcdefaHijklmnopqrstuvwxyz).Less( 0, 7) [true]
(GbcdefahiJklmnopqrstuvwxyz).Less( 0, 9) [true]
(GbcdefaHijklmnopqrstuvwxyz).Less( 7, 0) [false]
(GbcdefaHijklmnopqrstuvwxyz).Less( 0, 7) [true]
(GbcdefahIjklmnopqrstuvwxyz).Less( 0, 8) [true]
(GbcdefaHijklmnopqrstuvwxyz).Less( 7, 0) [false]
(GbcdefaHijklmnopqrstuvwxyz).Less( 0, 7) [true]
(GbcdefaHijklmnopqrstuvwxyz).Less( 0, 7) [true]
(GbcdefAhijklmnopqrstuvwxyz).Swap( 0, 6) [AbcdefGhijklmnopqrstuvwxyz]
(abcdefgHIjklmnopqrstuvwxyz).Less( 8, 7) [false]
(abcdefghIJklmnopqrstuvwxyz).Less( 9, 8) [false]
(abcdefghiJKlmnopqrstuvwxyz).Less(10, 9) [false]
(abcdefghijKLmnopqrstuvwxyz).Less(11, 10) [false]
(abcdefghijkLMnopqrstuvwxyz).Less(12, 11) [false]
(ABcdefghijklmnopqrstuvwxyz).Less( 1, 0) [false]
(aBCdefghijklmnopqrstuvwxyz).Less( 2, 1) [false]
(abCDefghijklmnopqrstuvwxyz).Less( 3, 2) [false]
(abcDEfghijklmnopqrstuvwxyz).Less( 4, 3) [false]
(abcdEFghijklmnopqrstuvwxyz).Less( 5, 4) [false]
Calls: {Len:1 Less:122 Swap:6}
Less: {Min:3 Max:80 Mean:4.6923075 Std:17.449509}
Swap: {Min:0 Max:4 Mean:0.23076923 Std:1.0348942}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment