{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/16063","repository_url":"https://api.github.com/repos/JuliaLang/julia","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/16063/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/16063/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/16063/events","html_url":"https://github.com/JuliaLang/julia/issues/16063","id":151277822,"number":16063,"title":"UnitRange Performance","user":{"login":"JaredCrean2","id":10292902,"avatar_url":"https://avatars.githubusercontent.com/u/10292902?v=3","gravatar_id":"","url":"https://api.github.com/users/JaredCrean2","html_url":"https://github.com/JaredCrean2","followers_url":"https://api.github.com/users/JaredCrean2/followers","following_url":"https://api.github.com/users/JaredCrean2/following{/other_user}","gists_url":"https://api.github.com/users/JaredCrean2/gists{/gist_id}","starred_url":"https://api.github.com/users/JaredCrean2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JaredCrean2/subscriptions","organizations_url":"https://api.github.com/users/JaredCrean2/orgs","repos_url":"https://api.github.com/users/JaredCrean2/repos","events_url":"https://api.github.com/users/JaredCrean2/events{/privacy}","received_events_url":"https://api.github.com/users/JaredCrean2/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":null,"comments":16,"created_at":"2016-04-27T01:40:32Z","updated_at":"2016-04-28T02:29:34Z","closed_at":null,"body":"I did a benchmark and found that summing a UnitRange is slower than summing the equivalent array:\r\n\r\n```julia\r\nfunction sumit{T}(arr::AbstractArray{T})\r\n\r\n  val = zero(T)\r\n  for i=1:length(arr)\r\n    val += arr[i]\r\n  end\r\n\r\n  return val\r\nend\r\n\r\nrng = 1:10000000\r\nrng_arr = collect(rng)\r\n\r\n@time sumit(rng)\r\n@time sumit(rng_arr)\r\n\r\nprintln(\"final results:\")\r\nprintln(\"sizeof(array) = \", sizeof(rng_arr))\r\n@time sumit(rng)\r\n@time sumit(rng_arr)\r\n```\r\n\r\nresults:\r\n```\r\n$ julia4 --check-bounds=no ./tmp.jl \r\n  0.039517 seconds (2.28 k allocations: 118.851 KB)\r\n  0.013272 seconds (1.98 k allocations: 100.646 KB)\r\nfinal results:\r\nsizeof(array) = 80000000\r\n  0.036911 seconds (5 allocations: 176 bytes)  # UnitRange\r\n  0.008454 seconds (5 allocations: 176 bytes)  # array\r\n```\r\n\r\nversioninfo:\r\n```\r\nJulia Version 0.4.4-pre+35\r\nCommit 1a9429e* (2016-02-12 13:21 UTC)\r\nPlatform Info:\r\n  System: Linux (x86_64-linux-gnu)\r\n  CPU: Intel(R) Core(TM) i7 CPU       Q 820  @ 1.73GHz\r\n  WORD_SIZE: 64\r\n  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Nehalem)\r\n  LAPACK: libopenblas64_\r\n  LIBM: libopenlibm\r\n  LLVM: libLLVM-3.3\r\n```\r\n\r\nThe array is large enough that it does not fit into cache, so I would have expected the UnitRange to be faster because it uses far less memory."},"comment":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/comments/215290165","html_url":"https://github.com/JuliaLang/julia/issues/16063#issuecomment-215290165","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/16063","id":215290165,"user":{"login":"blakejohnson","id":866695,"avatar_url":"https://avatars.githubusercontent.com/u/866695?v=3","gravatar_id":"","url":"https://api.github.com/users/blakejohnson","html_url":"https://github.com/blakejohnson","followers_url":"https://api.github.com/users/blakejohnson/followers","following_url":"https://api.github.com/users/blakejohnson/following{/other_user}","gists_url":"https://api.github.com/users/blakejohnson/gists{/gist_id}","starred_url":"https://api.github.com/users/blakejohnson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blakejohnson/subscriptions","organizations_url":"https://api.github.com/users/blakejohnson/orgs","repos_url":"https://api.github.com/users/blakejohnson/repos","events_url":"https://api.github.com/users/blakejohnson/events{/privacy}","received_events_url":"https://api.github.com/users/blakejohnson/received_events","type":"User","site_admin":false},"created_at":"2016-04-28T02:29:34Z","updated_at":"2016-04-28T02:29:34Z","body":"> Automatic bounds check removal isn't that interesting to me, because for any run where I really care about performance, I will use `julia --check-bounds=no` to get rid of all bounds checking everywhere.\r\n\r\n@mbauman was right when he noted above that the `--check-bounds=no` flag does not turn off *all* bounds checking, just bounds checks of Julia's native array type. So, automatic bounds checking removal should still be of interest to you."}}