{"action":"opened","issue":{"url":"https://api.github.com/repos/serge-sans-paille/pythran/issues/1111","repository_url":"https://api.github.com/repos/serge-sans-paille/pythran","labels_url":"https://api.github.com/repos/serge-sans-paille/pythran/issues/1111/labels{/name}","comments_url":"https://api.github.com/repos/serge-sans-paille/pythran/issues/1111/comments","events_url":"https://api.github.com/repos/serge-sans-paille/pythran/issues/1111/events","html_url":"https://github.com/serge-sans-paille/pythran/issues/1111","id":384411103,"node_id":"MDU6SXNzdWUzODQ0MTExMDM=","number":1111,"title":"Pythran much slower than Numpy to generate random numbers","user":{"login":"paugier","id":8842662,"node_id":"MDQ6VXNlcjg4NDI2NjI=","avatar_url":"https://avatars0.githubusercontent.com/u/8842662?v=4","gravatar_id":"","url":"https://api.github.com/users/paugier","html_url":"https://github.com/paugier","followers_url":"https://api.github.com/users/paugier/followers","following_url":"https://api.github.com/users/paugier/following{/other_user}","gists_url":"https://api.github.com/users/paugier/gists{/gist_id}","starred_url":"https://api.github.com/users/paugier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paugier/subscriptions","organizations_url":"https://api.github.com/users/paugier/orgs","repos_url":"https://api.github.com/users/paugier/repos","events_url":"https://api.github.com/users/paugier/events{/privacy}","received_events_url":"https://api.github.com/users/paugier/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-11-26T16:31:19Z","updated_at":"2018-11-26T16:31:19Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"### Pythran slower than Numpy...\r\n\r\nWe have a big performance issue with random number generation:\r\n\r\n```\r\n# tmp_rand.py\r\nimport numpy as np\r\n# pythran export rand2d(int)\r\ndef rand2d(n):\r\n    return np.random.rand(n, n)\r\n```\r\ncompiled with `pythran -march=native -DUSE_XSIMD tmp_rand.py -o tmp_rand_pythran.so`\r\n\r\nWith Numpy:\r\n```\r\nIn [1]: from tmp_rand import rand2d as rand2d_py                                  \r\nIn [2]: for n in [100, 1000, 2000, 4000, 10000]: \r\n   ...:     %timeit rand2d_py(n) \r\n   ...:                                                                           \r\n107 µs ± 32.5 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)\r\n10.5 ms ± 3.31 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\r\n42.1 ms ± 6.91 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\r\n217 ms ± 204 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)\r\n1.35 s ± 1.86 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\r\n```\r\n\r\nWith Pythran:\r\n```\r\nIn [1]: from tmp_rand_pythran import rand2d                                       \r\nIn [2]: for n in [100, 1000, 2000, 4000, 10000]: \r\n   ...:     %timeit rand2d(n) \r\n   ...:                                                                           \r\n942 µs ± 322 ns per loop (mean ± std. dev. of 7 runs, 1000 loops each)\r\n94.2 ms ± 68.4 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\r\n378 ms ± 2.75 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\r\n1.56 s ± 422 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)\r\n9.72 s ± 875 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)\r\n```\r\n\r\nOups, Pythran is approximately 10 times slower than Numpy to generate random numbers...\r\n\r\nSince many benchmarks involve random number generation, Pythran gets really bad results for these benchmarks because of this random generation issue!  I know that random number generation performance is not be so important in most codes, but communication matters...So silly micro-benchmarks matter :slightly_smiling_face: \r\n\r\nNote that it seems to be a regression since Numpy and Pythran performance were similar some months ago (#759 ).\r\n\r\n### Numpy much slower than other solutions for random number generation\r\n\r\nNote that random number generation is also known to be quite slow with Numpy (see for example https://software.intel.com/en-us/blogs/2016/06/15/faster-random-number-generation-in-intel-distribution-for-python and https://github.com/numpy/numpy/issues/6967).\r\n\r\nJulia random generation is very efficient (and Julia micro-benchmarks are full of random number generation...). https://github.com/fluiddyn/BenchmarksPythonJuliaAndCo/tree/master/JuMicroBenchmarks shows that Numpy is 7.5 slower than Julia (so Pythran is ~70 slower than Julia) for this!\r\n\r\nrandomgen (https://github.com/bashtage/randomgen) is a serious Python package (code in Cython) for quite fast random number generation.\r\n\r\nFor random number generation in benchmarks, it would make sens to use it so I think it would make sens to support a tiny part of the API of randomgen in Pythran. Just this would be sufficient in many cases for benchmarks:\r\n\r\n```\r\nfrom randomgen import RandomGenerator\r\n# Default basic PRNG is Xoroshiro128\r\nrnd = RandomGenerator()\r\nrnd.random_uintegers(1000000, bits=32)\r\nrnd.rand(1000, 1000)\r\n```\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}}
{"actor":{"display_login":"paugier"}}