{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/9832","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/9832/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/9832/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/9832/events","html_url":"https://github.com/JuliaLang/julia/issues/9832","id":54709525,"number":9832,"title":"sort() and sortrows() are slow for numerical arrays","user":{"login":"PetrKryslUCSD","id":9855832,"avatar_url":"https://avatars.githubusercontent.com/u/9855832?v=3","gravatar_id":"","url":"https://api.github.com/users/PetrKryslUCSD","html_url":"https://github.com/PetrKryslUCSD","followers_url":"https://api.github.com/users/PetrKryslUCSD/followers","following_url":"https://api.github.com/users/PetrKryslUCSD/following{/other_user}","gists_url":"https://api.github.com/users/PetrKryslUCSD/gists{/gist_id}","starred_url":"https://api.github.com/users/PetrKryslUCSD/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PetrKryslUCSD/subscriptions","organizations_url":"https://api.github.com/users/PetrKryslUCSD/orgs","repos_url":"https://api.github.com/users/PetrKryslUCSD/repos","events_url":"https://api.github.com/users/PetrKryslUCSD/events{/privacy}","received_events_url":"https://api.github.com/users/PetrKryslUCSD/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/JuliaLang/julia/labels/performance","name":"performance","color":"d7e102"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/JuliaLang/julia/milestones/11","html_url":"https://github.com/JuliaLang/julia/milestones/0.4.0","labels_url":"https://api.github.com/repos/JuliaLang/julia/milestones/11/labels","id":748886,"number":11,"title":"0.4.0","description":"For tracking release-defining items for 0.4: important new features, breaking changes, and blocking bugs.\r\n\r\nAfter a brief period for deciding scope, adding issues to this milestone is not allowed. Once the items in this milestone are done, 0.4 will enter its stabilizing period and a release candidate can be made soon after.","creator":{"login":"JeffBezanson","id":744556,"avatar_url":"https://avatars.githubusercontent.com/u/744556?v=3","gravatar_id":"","url":"https://api.github.com/users/JeffBezanson","html_url":"https://github.com/JeffBezanson","followers_url":"https://api.github.com/users/JeffBezanson/followers","following_url":"https://api.github.com/users/JeffBezanson/following{/other_user}","gists_url":"https://api.github.com/users/JeffBezanson/gists{/gist_id}","starred_url":"https://api.github.com/users/JeffBezanson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JeffBezanson/subscriptions","organizations_url":"https://api.github.com/users/JeffBezanson/orgs","repos_url":"https://api.github.com/users/JeffBezanson/repos","events_url":"https://api.github.com/users/JeffBezanson/events{/privacy}","received_events_url":"https://api.github.com/users/JeffBezanson/received_events","type":"User","site_admin":false},"open_issues":27,"closed_issues":34,"state":"open","created_at":"2014-08-10T18:13:46Z","updated_at":"2015-04-20T09:45:00Z","due_on":"2015-06-20T18:30:00Z","closed_at":null},"comments":11,"created_at":"2015-01-18T20:47:22Z","updated_at":"2015-04-20T09:56:11Z","closed_at":null,"body":"Julia  sorting functions are slow compared to Matlab. \r\n\r\nMatlab R2012b sorting of integer arrays:\r\n````\r\n>> a=randi(30000000,30000000,2);\r\n>> tic; b=sort(a,2); toc\r\nElapsed time is 0.882043 seconds.\r\n>> tic; b=sort(a,2); toc\r\nElapsed time is 0.903528 seconds.\r\n>> tic; b=sort(a,2); toc\r\nElapsed time is 0.900367 seconds.\r\n````\r\n````\r\nJulia sorting of integer arrays:\r\njulia> a=rand(Int64,30000000,2);\r\n\r\njulia> @time sort(a,2);\r\nelapsed time: 46.625749977 seconds (17279978752 bytes allocated, 19.15% gc time)\r\n````\r\n\r\nThe Julia sort() is more than 40 times slower than Matlab.\r\n\r\nThe sortrows() has a similar problem.  Still working with the same 30,000,000 x 2 array size:\r\n````\r\n>> tic; c=sortrows(b); toc\r\nElapsed time is 12.071053 seconds.\r\n````\r\nCompare with\r\n````\r\njulia> @time sortrows(a);\r\nelapsed time: 158.761497384 seconds (5765741164 bytes allocated, 3.42% gc time)\r\n````\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/comments/94411860","html_url":"https://github.com/JuliaLang/julia/issues/9832#issuecomment-94411860","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/9832","id":94411860,"user":{"login":"ViralBShah","id":744411,"avatar_url":"https://avatars.githubusercontent.com/u/744411?v=3","gravatar_id":"","url":"https://api.github.com/users/ViralBShah","html_url":"https://github.com/ViralBShah","followers_url":"https://api.github.com/users/ViralBShah/followers","following_url":"https://api.github.com/users/ViralBShah/following{/other_user}","gists_url":"https://api.github.com/users/ViralBShah/gists{/gist_id}","starred_url":"https://api.github.com/users/ViralBShah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ViralBShah/subscriptions","organizations_url":"https://api.github.com/users/ViralBShah/orgs","repos_url":"https://api.github.com/users/ViralBShah/repos","events_url":"https://api.github.com/users/ViralBShah/events{/privacy}","received_events_url":"https://api.github.com/users/ViralBShah/received_events","type":"User","site_admin":false},"created_at":"2015-04-20T09:56:11Z","updated_at":"2015-04-20T09:56:11Z","body":"I was just experimenting with slicing instead of using subarrays, and it is not any faster for sortrows. I also tried reinterpreting to a Vector of tuples for sortrows, but that blows up the memory usage and is significantly slower.\r\n\r\nFor sortrows on a few columns, I think the simplest thing may be to do something like:\r\n````\r\nfunction mysortrows{T}(A::AbstractMatrix{T}; kws...)\r\n    for i in size(A,2):-1:1\r\n        p = sortperm(A[:,i])\r\n        A = A[p,:]\r\n    end\r\n    A\r\nend\r\n````\r\n"}}