{"action":"created","issue":{"url":"https://api.github.com/repos/nim-lang/Nim/issues/3084","labels_url":"https://api.github.com/repos/nim-lang/Nim/issues/3084/labels{/name}","comments_url":"https://api.github.com/repos/nim-lang/Nim/issues/3084/comments","events_url":"https://api.github.com/repos/nim-lang/Nim/issues/3084/events","html_url":"https://github.com/nim-lang/Nim/issues/3084","id":93755157,"number":3084,"title":"Slow lines reading (even slower than python)","user":{"login":"scriptum","id":695971,"avatar_url":"https://avatars.githubusercontent.com/u/695971?v=3","gravatar_id":"","url":"https://api.github.com/users/scriptum","html_url":"https://github.com/scriptum","followers_url":"https://api.github.com/users/scriptum/followers","following_url":"https://api.github.com/users/scriptum/following{/other_user}","gists_url":"https://api.github.com/users/scriptum/gists{/gist_id}","starred_url":"https://api.github.com/users/scriptum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scriptum/subscriptions","organizations_url":"https://api.github.com/users/scriptum/orgs","repos_url":"https://api.github.com/users/scriptum/repos","events_url":"https://api.github.com/users/scriptum/events{/privacy}","received_events_url":"https://api.github.com/users/scriptum/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/nim-lang/Nim/labels/Medium%20Priority","name":"Medium Priority","color":"f7c6c7"},{"url":"https://api.github.com/repos/nim-lang/Nim/labels/Stdlib","name":"Stdlib","color":"eb6420"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":26,"created_at":"2015-07-08T10:17:32Z","updated_at":"2015-08-27T10:54:25Z","closed_at":null,"body":"I tested only naive implementations for C, Nim, Python in Linux x86_64:\r\n```C\r\n/* C */\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n\r\nint main(int argc, char **argv)\r\n{\r\n\tchar *buf = NULL;\r\n\tsize_t i = 0, len;\r\n\twhile(getline(&buf, &len, stdin) != -1) i++;\r\n\tprintf(\"%d\\n\", i);\r\n\tfree(buf);\r\n}\r\n```\r\n```Python\r\n# Python\r\nimport sys\r\ni = 0\r\nfor line in sys.stdin:\r\n\ti+=1\r\nprint i\r\n```\r\n```Nimrod\r\n# Nim\r\nvar i = 0\r\n# ugly but faster because of string copying\r\nproc main()=\r\n  for line in stdin.lines:\r\n    inc i\r\n  echo i\r\nmain()\r\n```\r\nGenerate test data (100MB):\r\n```Bash\r\ntr -c [:print:] ' ' </dev/urandom | fold -w1000 | head -100000 > test.data\r\n```\r\nAnd test like this: `./test < test.data`\r\n\r\nResults:\r\n* Nim (`gcc -O2`): 0.62\r\n* Nim (`gcc -O3`): 0.31\r\n* Python: 0.059\r\n* C: 0.031"},"comment":{"url":"https://api.github.com/repos/nim-lang/Nim/issues/comments/135381372","html_url":"https://github.com/nim-lang/Nim/issues/3084#issuecomment-135381372","issue_url":"https://api.github.com/repos/nim-lang/Nim/issues/3084","id":135381372,"user":{"login":"jlp765","id":5141524,"avatar_url":"https://avatars.githubusercontent.com/u/5141524?v=3","gravatar_id":"","url":"https://api.github.com/users/jlp765","html_url":"https://github.com/jlp765","followers_url":"https://api.github.com/users/jlp765/followers","following_url":"https://api.github.com/users/jlp765/following{/other_user}","gists_url":"https://api.github.com/users/jlp765/gists{/gist_id}","starred_url":"https://api.github.com/users/jlp765/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jlp765/subscriptions","organizations_url":"https://api.github.com/users/jlp765/orgs","repos_url":"https://api.github.com/users/jlp765/repos","events_url":"https://api.github.com/users/jlp765/events{/privacy}","received_events_url":"https://api.github.com/users/jlp765/received_events","type":"User","site_admin":false},"created_at":"2015-08-27T10:54:25Z","updated_at":"2015-08-27T10:54:25Z","body":"Using devel branch 0.11.3, Nim is faster than python on my win7 machine.\r\n(You do need to compile with ``-d:release``)\r\nI think this is no longer an issue."}}