{"action":"created","issue":{"url":"https://api.github.com/repos/kostya/benchmarks/issues/9","labels_url":"https://api.github.com/repos/kostya/benchmarks/issues/9/labels{/name}","comments_url":"https://api.github.com/repos/kostya/benchmarks/issues/9/comments","events_url":"https://api.github.com/repos/kostya/benchmarks/issues/9/events","html_url":"https://github.com/kostya/benchmarks/issues/9","id":65783481,"number":9,"title":"Julia code runs in global scope","user":{"login":"dextorious","id":526018,"avatar_url":"https://avatars.githubusercontent.com/u/526018?v=3","gravatar_id":"","url":"https://api.github.com/users/dextorious","html_url":"https://github.com/dextorious","followers_url":"https://api.github.com/users/dextorious/followers","following_url":"https://api.github.com/users/dextorious/following{/other_user}","gists_url":"https://api.github.com/users/dextorious/gists{/gist_id}","starred_url":"https://api.github.com/users/dextorious/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dextorious/subscriptions","organizations_url":"https://api.github.com/users/dextorious/orgs","repos_url":"https://api.github.com/users/dextorious/repos","events_url":"https://api.github.com/users/dextorious/events{/privacy}","received_events_url":"https://api.github.com/users/dextorious/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-04-01T21:33:10Z","updated_at":"2015-04-06T23:54:30Z","closed_at":"2015-04-02T12:53:30Z","body":"In Julia running code outside of predefined functions carries a heavy performance penalty. For instance, simply rewriting the matrix multiplication benchmark as follows yields a performance improvement by a factor of 3 on my machine:\r\n\r\nfunction matgen(n)\r\n\ttmp = 1.0 / n / n\r\n\t[ float32(tmp * (i - j) * (i + j - 2)) for i=1:n, j=1:n ]\r\nend\r\n\r\nfunction main()\r\n\tn = 100\r\n\tif length(ARGS) >= 1\r\n  \t\tn = int(ARGS[1])\r\n\tend\r\n\tt = time()\r\n\tn = int(n / 2 * 2)\r\n\ta = matgen(n)\r\n\tb = matgen(n)\r\n\tc = a * b\r\n\tv = int(n/2) + 1\r\n\tprintln(c[v, v])\r\n\tprintln(time() - t)\r\nend\r\n\r\nmain()\r\nmain()\r\n\r\nThe same goes for the other benchmarks. Technically, comprehensions are fairly slow too (compared to unrolled @simd/@inbounds annotated for loops), but the matrix generation doesn't particularly matter in this benchmark. Also note that the main() function is invoked twice here to show the kind of performance improvement the JIT produces (roughly 300 times on my machine). In general, it is good practice in Julia to first run performance sensitive functions on a tiny dataset to invoke the JIT, then run the actual computation.\r\n\r\nP.S. Also note that this particular benchmark implementation essentially measures the performance of whatever OpenBLAS version you compiled Julia to use and virtually any language should be able to obtain similar results."},"comment":{"url":"https://api.github.com/repos/kostya/benchmarks/issues/comments/90290861","html_url":"https://github.com/kostya/benchmarks/issues/9#issuecomment-90290861","issue_url":"https://api.github.com/repos/kostya/benchmarks/issues/9","id":90290861,"user":{"login":"tkelman","id":5934628,"avatar_url":"https://avatars.githubusercontent.com/u/5934628?v=3","gravatar_id":"","url":"https://api.github.com/users/tkelman","html_url":"https://github.com/tkelman","followers_url":"https://api.github.com/users/tkelman/followers","following_url":"https://api.github.com/users/tkelman/following{/other_user}","gists_url":"https://api.github.com/users/tkelman/gists{/gist_id}","starred_url":"https://api.github.com/users/tkelman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tkelman/subscriptions","organizations_url":"https://api.github.com/users/tkelman/orgs","repos_url":"https://api.github.com/users/tkelman/repos","events_url":"https://api.github.com/users/tkelman/events{/privacy}","received_events_url":"https://api.github.com/users/tkelman/received_events","type":"User","site_admin":false},"created_at":"2015-04-06T23:54:30Z","updated_at":"2015-04-06T23:54:30Z","body":"The Julia code is still written as if it's Python, no wonder it's running slowly. Julia types should not have function members, that's an OO anti-pattern."}}