{"action":"created","issue":{"url":"https://api.github.com/repos/nodejs/node/issues/7750","repository_url":"https://api.github.com/repos/nodejs/node","labels_url":"https://api.github.com/repos/nodejs/node/issues/7750/labels{/name}","comments_url":"https://api.github.com/repos/nodejs/node/issues/7750/comments","events_url":"https://api.github.com/repos/nodejs/node/issues/7750/events","html_url":"https://github.com/nodejs/node/issues/7750","id":165809508,"number":7750,"title":"Why is toString so slow compared to manual concatenation?","user":{"login":"githubaccount624","id":20170894,"avatar_url":"https://avatars.githubusercontent.com/u/20170894?v=3","gravatar_id":"","url":"https://api.github.com/users/githubaccount624","html_url":"https://github.com/githubaccount624","followers_url":"https://api.github.com/users/githubaccount624/followers","following_url":"https://api.github.com/users/githubaccount624/following{/other_user}","gists_url":"https://api.github.com/users/githubaccount624/gists{/gist_id}","starred_url":"https://api.github.com/users/githubaccount624/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/githubaccount624/subscriptions","organizations_url":"https://api.github.com/users/githubaccount624/orgs","repos_url":"https://api.github.com/users/githubaccount624/repos","events_url":"https://api.github.com/users/githubaccount624/events{/privacy}","received_events_url":"https://api.github.com/users/githubaccount624/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/nodejs/node/labels/buffer","name":"buffer","color":"f7c6c7"},{"url":"https://api.github.com/repos/nodejs/node/labels/performance","name":"performance","color":"5319e7"},{"url":"https://api.github.com/repos/nodejs/node/labels/question","name":"question","color":"cc317c"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":11,"created_at":"2016-07-15T15:09:45Z","updated_at":"2016-07-18T07:41:18Z","closed_at":"2016-07-18T07:41:18Z","body":"Using the latest version of node:\r\n\r\n`return bytes.slice(byteOffset, byteOffset + strLen).toString('ascii');` \r\n\r\ntakes around 200 milliseconds (in a looped benchmark).\r\n\r\n    var str = \"\";\r\n    for (var i = 0; i < strLen; i++) {\r\n      str += String.fromCharCode(bytes[i + byteOffset]);\r\n    }\r\n    return str;\r\n\r\nTakes around 100 ms. The second one manually concatenates a string each iteration. Also I'd imagine the first could practically just do a memcpy since it's ASCII. Why the stark difference?\r\n\r\nThis also applies to encoding as well. Manually iterating through is much faster than `buffer.write`"},"comment":{"url":"https://api.github.com/repos/nodejs/node/issues/comments/233255717","html_url":"https://github.com/nodejs/node/issues/7750#issuecomment-233255717","issue_url":"https://api.github.com/repos/nodejs/node/issues/7750","id":233255717,"user":{"login":"bnoordhuis","id":275871,"avatar_url":"https://avatars.githubusercontent.com/u/275871?v=3","gravatar_id":"","url":"https://api.github.com/users/bnoordhuis","html_url":"https://github.com/bnoordhuis","followers_url":"https://api.github.com/users/bnoordhuis/followers","following_url":"https://api.github.com/users/bnoordhuis/following{/other_user}","gists_url":"https://api.github.com/users/bnoordhuis/gists{/gist_id}","starred_url":"https://api.github.com/users/bnoordhuis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bnoordhuis/subscriptions","organizations_url":"https://api.github.com/users/bnoordhuis/orgs","repos_url":"https://api.github.com/users/bnoordhuis/repos","events_url":"https://api.github.com/users/bnoordhuis/events{/privacy}","received_events_url":"https://api.github.com/users/bnoordhuis/received_events","type":"User","site_admin":false},"created_at":"2016-07-18T07:41:18Z","updated_at":"2016-07-18T07:41:18Z","body":"Okay, let's close."}}
{"actor":{"display_login":"bnoordhuis"}}