{"action":"opened","issue":{"url":"https://api.github.com/repos/cosmo-ethz/hope/issues/52","repository_url":"https://api.github.com/repos/cosmo-ethz/hope","labels_url":"https://api.github.com/repos/cosmo-ethz/hope/issues/52/labels{/name}","comments_url":"https://api.github.com/repos/cosmo-ethz/hope/issues/52/comments","events_url":"https://api.github.com/repos/cosmo-ethz/hope/issues/52/events","html_url":"https://github.com/cosmo-ethz/hope/issues/52","id":167058050,"number":52,"title":"ln_python 10th polynomial benchmark variant","user":{"login":"pigay","id":754327,"avatar_url":"https://avatars.githubusercontent.com/u/754327?v=3","gravatar_id":"","url":"https://api.github.com/users/pigay","html_url":"https://github.com/pigay","followers_url":"https://api.github.com/users/pigay/followers","following_url":"https://api.github.com/users/pigay/following{/other_user}","gists_url":"https://api.github.com/users/pigay/gists{/gist_id}","starred_url":"https://api.github.com/users/pigay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pigay/subscriptions","organizations_url":"https://api.github.com/users/pigay/orgs","repos_url":"https://api.github.com/users/pigay/repos","events_url":"https://api.github.com/users/pigay/events{/privacy}","received_events_url":"https://api.github.com/users/pigay/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-07-22T14:30:37Z","updated_at":"2016-07-22T14:30:37Z","closed_at":null,"body":"Hi,\r\n\r\nI would like to contribute a variant on ln_python benchmark.\r\n\r\nInstead of using numpy slice, we directly access to array elements inside a loop. This is of course terribly slow for interpreted Python but seems to be faster with compiled code like generated with HOPE and numba. In my tests, it happens to be fairly faster than the numpy slice version.\r\n\r\nIn the following code, I had to add a `N` parameter beacuse HOPE doesn't support `np.ndarray.size` attribute. I also use a Horner schema for the polynomial evaluation.\r\n```python\r\ndef loop_ln_python(X,Y, N):\r\n    for i in xrange(N):\r\n        xm1 = X[i] - 1.\r\n        tmp = xm1 * (1./9.) - 1./8.\r\n        tmp = tmp * xm1 + 1./7.\r\n        tmp = tmp * xm1 - 1./6.\r\n        tmp = tmp * xm1 + 1./5.\r\n        tmp = tmp * xm1 - 1./4.\r\n        tmp = tmp * xm1 + 1./3.\r\n        tmp = tmp * xm1 - 1./2.\r\n        tmp = tmp * xm1 + 1.\r\n        Y[i] = tmp * xm1\r\n\r\n        \r\n\r\nloop_ln_hope = hope.jit(loop_ln_python)\r\nloop_ln_numba = numba.autojit(loop_ln_python)\r\n```\r\n\r\nI test with the following:\r\n```python\r\nX = np.random.random(10000).astype(np.float64)\r\nY = np.ones_like(X)\r\n\r\nloop_ln_hope(X, Y, len(X))\r\nloop_ln_numba(X, Y, len(X))\r\n\r\n%timeit loop_ln_python(X, Y, len(X))\r\n%timeit loop_ln_hope(X, Y, len(X))\r\n%timeit loop_ln_numba(X, Y, len(X))\r\n```\r\n\r\nOn my laptop, I get the following timings:\r\n```\r\n100 loops, best of 3: 15.1 ms per loop\r\n10000 loops, best of 3: 46.1 µs per loop\r\n100000 loops, best of 3: 12.7 µs per loop\r\n```\r\n\r\nTo be compared to the `ln_python_exp()` timings:\r\n```\r\n1000 loops, best of 3: 257 µs per loop\r\n10000 loops, best of 3: 76.8 µs per loop\r\n10000 loops, best of 3: 110 µs per loop\r\n```\r\n\r\nI hope it will be of some interest for you.\r\n\r\nFor the sake of completeness, we can write a Horner schema version that doesn't add much to the compiled performances but which is more fair for numpy interpreted code:\r\n```python\r\ndef ln_python_horner(X, Y):\r\n    Xm1 = X - 1\r\n    Y[:] = Xm1 / 9. - 1./8.\r\n    Y[:] = Y * Xm1 + 1./7.\r\n    Y[:] = Y * Xm1 - 1./6.\r\n    Y[:] = Y * Xm1 + 1./5.\r\n    Y[:] = Y * Xm1 - 1./4.\r\n    Y[:] = Y * Xm1 + 1./3.\r\n    Y[:] = Y * Xm1 - 1./2.\r\n    Y[:] = Y * Xm1 + 1.\r\n    Y[:] = Y * Xm1\r\n\r\n```\r\nAnd with the timings:\r\n```\r\n10000 loops, best of 3: 169 µs per loop\r\n10000 loops, best of 3: 104 µs per loop\r\n10000 loops, best of 3: 119 µs per loop\r\n```\r\n\r\nAnyway, thanks for this nice package.\r\n\r\nCheers,\r\n\r\nPierre"}}
{"actor":{"display_login":"pigay"}}