{"action":"created","comment":{"url":"https://api.github.com/repos/az0/bleachbit/pulls/comments/47600730","id":47600730,"diff_hunk":"@@ -92,31 +92,39 @@ def __random_string(length):\n \n \n def bytes_to_human(bytes_i):\n-    \"\"\"Display a file size in human terms (megabytes, etc.) using SI standard\"\"\"\n+    \"\"\"Display a file size in human terms (megabytes, etc.) using preferred standard (SI or IEC)\"\"\"\n \n-    storage_multipliers = {1000 ** 5: 'PB', 1000 ** 4: 'TB',\n-                           1000 ** 3: 'GB', 1000 ** 2: 'MB', 1000: 'kB', 1: 'B'}\n+    if bytes_i < 0:\n+        return '-' + bytes_to_human(-bytes_i)\n+\n+    from Options import options\n+    if options.get('units_iec'):\n+        prefixes = ['','Ki','Mi','Gi','Ti','Pi']\n+        base = 1024.0\n+    else:","path":"bleachbit/FileUtilities.py","position":16,"original_position":16,"commit_id":"283be71bfa451b537988f59f013c6f98603bb151","original_commit_id":"283be71bfa451b537988f59f013c6f98603bb151","user":{"login":"az0","id":933680,"avatar_url":"https://avatars.githubusercontent.com/u/933680?v=3","gravatar_id":"","url":"https://api.github.com/users/az0","html_url":"https://github.com/az0","followers_url":"https://api.github.com/users/az0/followers","following_url":"https://api.github.com/users/az0/following{/other_user}","gists_url":"https://api.github.com/users/az0/gists{/gist_id}","starred_url":"https://api.github.com/users/az0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/az0/subscriptions","organizations_url":"https://api.github.com/users/az0/orgs","repos_url":"https://api.github.com/users/az0/repos","events_url":"https://api.github.com/users/az0/events{/privacy}","received_events_url":"https://api.github.com/users/az0/received_events","type":"User","site_admin":false},"body":"Because this function can be called a thousand times (once for each file, like when cleaning localizations), I ran this benchmark in three scenarios\r\n````timeit.timeit('bleachbit.FileUtilities.bytes_to_human(100000)', setup='import bleachbit.FileUtilities', number=100000)````\r\n\r\nOriginal code: 4.7 seconds\r\nNew code: 9.2 seconds\r\nNew code that replaces conditional with two global variables: 4.2 seconds\r\n\r\nAnd just this one new line takes 3.5 seconds\r\n````timeit.timeit('options.get(\"units_iec\")',setup='from bleachbit.Options import options', number=100000)````\r\n\r\nHowever, bytes_to_human on 1000 files, which is more typical than 100,000 files, it is only 0.1 seconds, so maybe not worth optimizing.","created_at":"2015-12-15T06:31:57Z","updated_at":"2015-12-15T06:31:57Z","html_url":"https://github.com/az0/bleachbit/pull/111#discussion_r47600730","pull_request_url":"https://api.github.com/repos/az0/bleachbit/pulls/111","_links":{"self":{"href":"https://api.github.com/repos/az0/bleachbit/pulls/comments/47600730"},"html":{"href":"https://github.com/az0/bleachbit/pull/111#discussion_r47600730"},"pull_request":{"href":"https://api.github.com/repos/az0/bleachbit/pulls/111"}}},"pull_request":{"url":"https://api.github.com/repos/az0/bleachbit/pulls/111","id":53563186,"html_url":"https://github.com/az0/bleachbit/pull/111","diff_url":"https://github.com/az0/bleachbit/pull/111.diff","patch_url":"https://github.com/az0/bleachbit/pull/111.patch","issue_url":"https://api.github.com/repos/az0/bleachbit/issues/111","number":111,"state":"open","locked":false,"title":"Add option for preferred size prefixes (#103)","user":{"login":"tstenner","id":920936,"avatar_url":"https://avatars.githubusercontent.com/u/920936?v=3","gravatar_id":"","url":"https://api.github.com/users/tstenner","html_url":"https://github.com/tstenner","followers_url":"https://api.github.com/users/tstenner/followers","following_url":"https://api.github.com/users/tstenner/following{/other_user}","gists_url":"https://api.github.com/users/tstenner/gists{/gist_id}","starred_url":"https://api.github.com/users/tstenner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tstenner/subscriptions","organizations_url":"https://api.github.com/users/tstenner/orgs","repos_url":"https://api.github.com/users/tstenner/repos","events_url":"https://api.github.com/users/tstenner/events{/privacy}","received_events_url":"https://api.github.com/users/tstenner/received_events","type":"User","site_admin":false},"body":"This adds an option to switch between IEC and SI prefixes (see #103).\r\nIt also fixes the case where no value was returned if more than 1 petabytes were freed.","created_at":"2015-12-14T13:18:16Z","updated_at":"2015-12-15T06:31:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1606ef327a8a7827907bb018c2f28b4634cc45e3","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/az0/bleachbit/pulls/111/commits","review_comments_url":"https://api.github.com/repos/az0/bleachbit/pulls/111/comments","review_comment_url":"https://api.github.com/repos/az0/bleachbit/pulls/comments{/number}","comments_url":"https://api.github.com/repos/az0/bleachbit/issues/111/comments","statuses_url":"https://api.github.com/repos/az0/bleachbit/statuses/283be71bfa451b537988f59f013c6f98603bb151","head":{"label":"tstenner:prefixoptions","ref":"prefixoptions","sha":"283be71bfa451b537988f59f013c6f98603bb151","user":{"login":"tstenner","id":920936,"avatar_url":"https://avatars.githubusercontent.com/u/920936?v=3","gravatar_id":"","url":"https://api.github.com/users/tstenner","html_url":"https://github.com/tstenner","followers_url":"https://api.github.com/users/tstenner/followers","following_url":"https://api.github.com/users/tstenner/following{/other_user}","gists_url":"https://api.github.com/users/tstenner/gists{/gist_id}","starred_url":"https://api.github.com/users/tstenner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tstenner/subscriptions","organizations_url":"https://api.github.com/users/tstenner/orgs","repos_url":"https://api.github.com/users/tstenner/repos","events_url":"https://api.github.com/users/tstenner/events{/privacy}","received_events_url":"https://api.github.com/users/tstenner/received_events","type":"User","site_admin":false},"repo":{"id":22006510,"name":"bleachbit","full_name":"tstenner/bleachbit","owner":{"login":"tstenner","id":920936,"avatar_url":"https://avatars.githubusercontent.com/u/920936?v=3","gravatar_id":"","url":"https://api.github.com/users/tstenner","html_url":"https://github.com/tstenner","followers_url":"https://api.github.com/users/tstenner/followers","following_url":"https://api.github.com/users/tstenner/following{/other_user}","gists_url":"https://api.github.com/users/tstenner/gists{/gist_id}","starred_url":"https://api.github.com/users/tstenner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tstenner/subscriptions","organizations_url":"https://api.github.com/users/tstenner/orgs","repos_url":"https://api.github.com/users/tstenner/repos","events_url":"https://api.github.com/users/tstenner/events{/privacy}","received_events_url":"https://api.github.com/users/tstenner/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tstenner/bleachbit","description":"BleachBit system cleaner for Windows and Linux","fork":true,"url":"https://api.github.com/repos/tstenner/bleachbit","forks_url":"https://api.github.com/repos/tstenner/bleachbit/forks","keys_url":"https://api.github.com/repos/tstenner/bleachbit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tstenner/bleachbit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tstenner/bleachbit/teams","hooks_url":"https://api.github.com/repos/tstenner/bleachbit/hooks","issue_events_url":"https://api.github.com/repos/tstenner/bleachbit/issues/events{/number}","events_url":"https://api.github.com/repos/tstenner/bleachbit/events","assignees_url":"https://api.github.com/repos/tstenner/bleachbit/assignees{/user}","branches_url":"https://api.github.com/repos/tstenner/bleachbit/branches{/branch}","tags_url":"https://api.github.com/repos/tstenner/bleachbit/tags","blobs_url":"https://api.github.com/repos/tstenner/bleachbit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tstenner/bleachbit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tstenner/bleachbit/git/refs{/sha}","trees_url":"https://api.github.com/repos/tstenner/bleachbit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tstenner/bleachbit/statuses/{sha}","languages_url":"https://api.github.com/repos/tstenner/bleachbit/languages","stargazers_url":"https://api.github.com/repos/tstenner/bleachbit/stargazers","contributors_url":"https://api.github.com/repos/tstenner/bleachbit/contributors","subscribers_url":"https://api.github.com/repos/tstenner/bleachbit/subscribers","subscription_url":"https://api.github.com/repos/tstenner/bleachbit/subscription","commits_url":"https://api.github.com/repos/tstenner/bleachbit/commits{/sha}","git_commits_url":"https://api.github.com/repos/tstenner/bleachbit/git/commits{/sha}","comments_url":"https://api.github.com/repos/tstenner/bleachbit/comments{/number}","issue_comment_url":"https://api.github.com/repos/tstenner/bleachbit/issues/comments{/number}","contents_url":"https://api.github.com/repos/tstenner/bleachbit/contents/{+path}","compare_url":"https://api.github.com/repos/tstenner/bleachbit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tstenner/bleachbit/merges","archive_url":"https://api.github.com/repos/tstenner/bleachbit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tstenner/bleachbit/downloads","issues_url":"https://api.github.com/repos/tstenner/bleachbit/issues{/number}","pulls_url":"https://api.github.com/repos/tstenner/bleachbit/pulls{/number}","milestones_url":"https://api.github.com/repos/tstenner/bleachbit/milestones{/number}","notifications_url":"https://api.github.com/repos/tstenner/bleachbit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tstenner/bleachbit/labels{/name}","releases_url":"https://api.github.com/repos/tstenner/bleachbit/releases{/id}","created_at":"2014-07-19T09:35:38Z","updated_at":"2015-03-19T09:30:10Z","pushed_at":"2015-12-14T17:33:50Z","git_url":"git://github.com/tstenner/bleachbit.git","ssh_url":"git@github.com:tstenner/bleachbit.git","clone_url":"https://github.com/tstenner/bleachbit.git","svn_url":"https://github.com/tstenner/bleachbit","homepage":"http://bleachbit.sourceforge.net","size":4300,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"az0:master","ref":"master","sha":"d9b0aaf5040c451294886a7c788f166180d42d68","user":{"login":"az0","id":933680,"avatar_url":"https://avatars.githubusercontent.com/u/933680?v=3","gravatar_id":"","url":"https://api.github.com/users/az0","html_url":"https://github.com/az0","followers_url":"https://api.github.com/users/az0/followers","following_url":"https://api.github.com/users/az0/following{/other_user}","gists_url":"https://api.github.com/users/az0/gists{/gist_id}","starred_url":"https://api.github.com/users/az0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/az0/subscriptions","organizations_url":"https://api.github.com/users/az0/orgs","repos_url":"https://api.github.com/users/az0/repos","events_url":"https://api.github.com/users/az0/events{/privacy}","received_events_url":"https://api.github.com/users/az0/received_events","type":"User","site_admin":false},"repo":{"id":17578592,"name":"bleachbit","full_name":"az0/bleachbit","owner":{"login":"az0","id":933680,"avatar_url":"https://avatars.githubusercontent.com/u/933680?v=3","gravatar_id":"","url":"https://api.github.com/users/az0","html_url":"https://github.com/az0","followers_url":"https://api.github.com/users/az0/followers","following_url":"https://api.github.com/users/az0/following{/other_user}","gists_url":"https://api.github.com/users/az0/gists{/gist_id}","starred_url":"https://api.github.com/users/az0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/az0/subscriptions","organizations_url":"https://api.github.com/users/az0/orgs","repos_url":"https://api.github.com/users/az0/repos","events_url":"https://api.github.com/users/az0/events{/privacy}","received_events_url":"https://api.github.com/users/az0/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/az0/bleachbit","description":"BleachBit system cleaner for Windows and Linux","fork":false,"url":"https://api.github.com/repos/az0/bleachbit","forks_url":"https://api.github.com/repos/az0/bleachbit/forks","keys_url":"https://api.github.com/repos/az0/bleachbit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/az0/bleachbit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/az0/bleachbit/teams","hooks_url":"https://api.github.com/repos/az0/bleachbit/hooks","issue_events_url":"https://api.github.com/repos/az0/bleachbit/issues/events{/number}","events_url":"https://api.github.com/repos/az0/bleachbit/events","assignees_url":"https://api.github.com/repos/az0/bleachbit/assignees{/user}","branches_url":"https://api.github.com/repos/az0/bleachbit/branches{/branch}","tags_url":"https://api.github.com/repos/az0/bleachbit/tags","blobs_url":"https://api.github.com/repos/az0/bleachbit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/az0/bleachbit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/az0/bleachbit/git/refs{/sha}","trees_url":"https://api.github.com/repos/az0/bleachbit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/az0/bleachbit/statuses/{sha}","languages_url":"https://api.github.com/repos/az0/bleachbit/languages","stargazers_url":"https://api.github.com/repos/az0/bleachbit/stargazers","contributors_url":"https://api.github.com/repos/az0/bleachbit/contributors","subscribers_url":"https://api.github.com/repos/az0/bleachbit/subscribers","subscription_url":"https://api.github.com/repos/az0/bleachbit/subscription","commits_url":"https://api.github.com/repos/az0/bleachbit/commits{/sha}","git_commits_url":"https://api.github.com/repos/az0/bleachbit/git/commits{/sha}","comments_url":"https://api.github.com/repos/az0/bleachbit/comments{/number}","issue_comment_url":"https://api.github.com/repos/az0/bleachbit/issues/comments{/number}","contents_url":"https://api.github.com/repos/az0/bleachbit/contents/{+path}","compare_url":"https://api.github.com/repos/az0/bleachbit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/az0/bleachbit/merges","archive_url":"https://api.github.com/repos/az0/bleachbit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/az0/bleachbit/downloads","issues_url":"https://api.github.com/repos/az0/bleachbit/issues{/number}","pulls_url":"https://api.github.com/repos/az0/bleachbit/pulls{/number}","milestones_url":"https://api.github.com/repos/az0/bleachbit/milestones{/number}","notifications_url":"https://api.github.com/repos/az0/bleachbit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/az0/bleachbit/labels{/name}","releases_url":"https://api.github.com/repos/az0/bleachbit/releases{/id}","created_at":"2014-03-10T01:40:31Z","updated_at":"2015-12-11T14:21:17Z","pushed_at":"2015-12-15T03:12:15Z","git_url":"git://github.com/az0/bleachbit.git","ssh_url":"git@github.com:az0/bleachbit.git","clone_url":"https://github.com/az0/bleachbit.git","svn_url":"https://github.com/az0/bleachbit","homepage":"http://bleachbit.sourceforge.net","size":4442,"stargazers_count":39,"watchers_count":39,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":27,"mirror_url":null,"open_issues_count":21,"forks":27,"open_issues":21,"watchers":39,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/az0/bleachbit/pulls/111"},"html":{"href":"https://github.com/az0/bleachbit/pull/111"},"issue":{"href":"https://api.github.com/repos/az0/bleachbit/issues/111"},"comments":{"href":"https://api.github.com/repos/az0/bleachbit/issues/111/comments"},"review_comments":{"href":"https://api.github.com/repos/az0/bleachbit/pulls/111/comments"},"review_comment":{"href":"https://api.github.com/repos/az0/bleachbit/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/az0/bleachbit/pulls/111/commits"},"statuses":{"href":"https://api.github.com/repos/az0/bleachbit/statuses/283be71bfa451b537988f59f013c6f98603bb151"}}}}