{"action":"created","comment":{"url":"https://api.github.com/repos/mozilla/activity-stream/pulls/comments/77720877","id":77720877,"diff_hunk":"@@ -0,0 +1,182 @@\n+/* globals XPCOMUtils, Services, Task */\n+\"use strict\";\n+\n+const {Cu} = require(\"chrome\");\n+Cu.import(\"resource://gre/modules/XPCOMUtils.jsm\");\n+Cu.import(\"resource://gre/modules/Services.jsm\");\n+\n+XPCOMUtils.defineLazyModuleGetter(this, \"Task\",\n+                                  \"resource://gre/modules/Task.jsm\");\n+// For the performance.now()\n+const performance = Services.appShell.hiddenDOMWindow.performance;\n+\n+/*\n+ * A simple benchmark framework that runs on top of jpm test\n+ *\n+ * Note that the timing resolution for the benchmark is microsecond\n+ *\n+ * Example:\n+\n+  function fib(n) {\n+    if (n < 2) {\n+      return n;\n+    }\n+\n+    return fib(n - 1) + fib(n - 2);\n+  }\n+\n+  exports.test_benchmark = function*() {\n+    let bench = new Benchmark(b => {\n+      for (let i = 0; i < b.N; i++) {\n+        fib(20);\n+      }\n+    });\n+    let result = yield bench.launch();\n+    console.log(result);\n+  };\n+*/\n+\n+/*\n+ * {Params} func is the benchmark function/generator that is of the following form\n+ *\n+   function(b) {\n+     for (let i = 0; i < b.N; i++) {\n+       // do your stuff here\n+     }\n+   }\n+ * Note that the framework will decide the best iteration number b.N based on\n+ * how fast the target benchmark function runs\n+ *\n+ * {Params} benchTime is the benchmark time in microseconds, by default it's one second\n+ */\n+function Benchmark(func, benchTime = 1e6) {\n+  this._failed = false;\n+  this._benchFunc = func;\n+  this._benchTime = benchTime;\n+  this._timerOn = false;\n+  this._start = 0;\n+  this._duration = 0;\n+  // N is public to the benchmark functions\n+  this.N = 0;\n+}\n+\n+Benchmark.prototype = {\n+  /*\n+   * Starts the timer for the benchmark. This function is called automatically\n+   * before each benchmark. It also can be used to resuming timing after the\n+   * stopTimer function call\n+   */\n+  startTimer() {\n+    if (!this._timerOn) {\n+      this._start = performance.now() * 1e3;\n+      this._timerOn = true;\n+    }\n+  },\n+\n+  /*\n+   * Resets the start timer if the timer is in use. It also zeros the benchmark's\n+   * duration\n+   */\n+  resetTimer() {\n+    if (this._timerOn) {\n+      this._start = performance.now() * 1e3;\n+    }\n+    this._duration = 0;\n+  },\n+\n+  /*\n+   * Stops the timer if the timer is in use. It also calculates the benchmark's\n+   * duration\n+   */\n+  stopTimer() {\n+    if (this._timerOn) {\n+      this._duration += (performance.now() * 1e3 - this._start);\n+      this._timerOn = false;\n+    }\n+  },\n+\n+  _usPerOp() {\n+    if (this.N <= 0) {\n+      return 0;","path":"test/lib/Benchmark.js","position":100,"original_position":100,"commit_id":"746cc964779337934ccf17c46cb1c2fc06cf981c","original_commit_id":"746cc964779337934ccf17c46cb1c2fc06cf981c","user":{"login":"dmose","id":425657,"avatar_url":"https://avatars.githubusercontent.com/u/425657?v=3","gravatar_id":"","url":"https://api.github.com/users/dmose","html_url":"https://github.com/dmose","followers_url":"https://api.github.com/users/dmose/followers","following_url":"https://api.github.com/users/dmose/following{/other_user}","gists_url":"https://api.github.com/users/dmose/gists{/gist_id}","starred_url":"https://api.github.com/users/dmose/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmose/subscriptions","organizations_url":"https://api.github.com/users/dmose/orgs","repos_url":"https://api.github.com/users/dmose/repos","events_url":"https://api.github.com/users/dmose/events{/privacy}","received_events_url":"https://api.github.com/users/dmose/received_events","type":"User","site_admin":false},"body":"Is it valid for this.N to go negative?  If so, please comment under what circumstances that would happen.  If not, perhaps we want to throw in that case?\r\n","created_at":"2016-09-06T21:16:06Z","updated_at":"2016-09-06T21:16:07Z","html_url":"https://github.com/mozilla/activity-stream/pull/1209#discussion_r77720877","pull_request_url":"https://api.github.com/repos/mozilla/activity-stream/pulls/1209","_links":{"self":{"href":"https://api.github.com/repos/mozilla/activity-stream/pulls/comments/77720877"},"html":{"href":"https://github.com/mozilla/activity-stream/pull/1209#discussion_r77720877"},"pull_request":{"href":"https://api.github.com/repos/mozilla/activity-stream/pulls/1209"}}},"pull_request":{"url":"https://api.github.com/repos/mozilla/activity-stream/pulls/1209","id":83820289,"html_url":"https://github.com/mozilla/activity-stream/pull/1209","diff_url":"https://github.com/mozilla/activity-stream/pull/1209.diff","patch_url":"https://github.com/mozilla/activity-stream/pull/1209.patch","issue_url":"https://api.github.com/repos/mozilla/activity-stream/issues/1209","number":1209,"state":"open","locked":false,"title":"feat(addon): add benchmarking support","user":{"login":"ncloudioj","id":1455254,"avatar_url":"https://avatars.githubusercontent.com/u/1455254?v=3","gravatar_id":"","url":"https://api.github.com/users/ncloudioj","html_url":"https://github.com/ncloudioj","followers_url":"https://api.github.com/users/ncloudioj/followers","following_url":"https://api.github.com/users/ncloudioj/following{/other_user}","gists_url":"https://api.github.com/users/ncloudioj/gists{/gist_id}","starred_url":"https://api.github.com/users/ncloudioj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ncloudioj/subscriptions","organizations_url":"https://api.github.com/users/ncloudioj/orgs","repos_url":"https://api.github.com/users/ncloudioj/repos","events_url":"https://api.github.com/users/ncloudioj/events{/privacy}","received_events_url":"https://api.github.com/users/ncloudioj/received_events","type":"User","site_admin":false},"body":"\n\n<!-- Reviewable:start -->\nThis change is [<img src=\"https://reviewable.io/review_button.svg\" height=\"34\" align=\"absmiddle\" alt=\"Reviewable\"/>](https://reviewable.io/reviews/mozilla/activity-stream/1209)\n<!-- Reviewable:end -->\n","created_at":"2016-09-02T15:26:08Z","updated_at":"2016-09-06T21:16:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"36fae3bdd8b7acaf8100ad4ac2f8e72d150a01ee","assignee":{"login":"dmose","id":425657,"avatar_url":"https://avatars.githubusercontent.com/u/425657?v=3","gravatar_id":"","url":"https://api.github.com/users/dmose","html_url":"https://github.com/dmose","followers_url":"https://api.github.com/users/dmose/followers","following_url":"https://api.github.com/users/dmose/following{/other_user}","gists_url":"https://api.github.com/users/dmose/gists{/gist_id}","starred_url":"https://api.github.com/users/dmose/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmose/subscriptions","organizations_url":"https://api.github.com/users/dmose/orgs","repos_url":"https://api.github.com/users/dmose/repos","events_url":"https://api.github.com/users/dmose/events{/privacy}","received_events_url":"https://api.github.com/users/dmose/received_events","type":"User","site_admin":false},"assignees":[{"login":"dmose","id":425657,"avatar_url":"https://avatars.githubusercontent.com/u/425657?v=3","gravatar_id":"","url":"https://api.github.com/users/dmose","html_url":"https://github.com/dmose","followers_url":"https://api.github.com/users/dmose/followers","following_url":"https://api.github.com/users/dmose/following{/other_user}","gists_url":"https://api.github.com/users/dmose/gists{/gist_id}","starred_url":"https://api.github.com/users/dmose/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmose/subscriptions","organizations_url":"https://api.github.com/users/dmose/orgs","repos_url":"https://api.github.com/users/dmose/repos","events_url":"https://api.github.com/users/dmose/events{/privacy}","received_events_url":"https://api.github.com/users/dmose/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/mozilla/activity-stream/pulls/1209/commits","review_comments_url":"https://api.github.com/repos/mozilla/activity-stream/pulls/1209/comments","review_comment_url":"https://api.github.com/repos/mozilla/activity-stream/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mozilla/activity-stream/issues/1209/comments","statuses_url":"https://api.github.com/repos/mozilla/activity-stream/statuses/746cc964779337934ccf17c46cb1c2fc06cf981c","head":{"label":"ncloudioj:benchmarking","ref":"benchmarking","sha":"746cc964779337934ccf17c46cb1c2fc06cf981c","user":{"login":"ncloudioj","id":1455254,"avatar_url":"https://avatars.githubusercontent.com/u/1455254?v=3","gravatar_id":"","url":"https://api.github.com/users/ncloudioj","html_url":"https://github.com/ncloudioj","followers_url":"https://api.github.com/users/ncloudioj/followers","following_url":"https://api.github.com/users/ncloudioj/following{/other_user}","gists_url":"https://api.github.com/users/ncloudioj/gists{/gist_id}","starred_url":"https://api.github.com/users/ncloudioj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ncloudioj/subscriptions","organizations_url":"https://api.github.com/users/ncloudioj/orgs","repos_url":"https://api.github.com/users/ncloudioj/repos","events_url":"https://api.github.com/users/ncloudioj/events{/privacy}","received_events_url":"https://api.github.com/users/ncloudioj/received_events","type":"User","site_admin":false},"repo":{"id":55420605,"name":"activity-streams","full_name":"ncloudioj/activity-streams","owner":{"login":"ncloudioj","id":1455254,"avatar_url":"https://avatars.githubusercontent.com/u/1455254?v=3","gravatar_id":"","url":"https://api.github.com/users/ncloudioj","html_url":"https://github.com/ncloudioj","followers_url":"https://api.github.com/users/ncloudioj/followers","following_url":"https://api.github.com/users/ncloudioj/following{/other_user}","gists_url":"https://api.github.com/users/ncloudioj/gists{/gist_id}","starred_url":"https://api.github.com/users/ncloudioj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ncloudioj/subscriptions","organizations_url":"https://api.github.com/users/ncloudioj/orgs","repos_url":"https://api.github.com/users/ncloudioj/repos","events_url":"https://api.github.com/users/ncloudioj/events{/privacy}","received_events_url":"https://api.github.com/users/ncloudioj/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ncloudioj/activity-streams","description":" MVP prototype add-on for activity streams","fork":true,"url":"https://api.github.com/repos/ncloudioj/activity-streams","forks_url":"https://api.github.com/repos/ncloudioj/activity-streams/forks","keys_url":"https://api.github.com/repos/ncloudioj/activity-streams/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ncloudioj/activity-streams/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ncloudioj/activity-streams/teams","hooks_url":"https://api.github.com/repos/ncloudioj/activity-streams/hooks","issue_events_url":"https://api.github.com/repos/ncloudioj/activity-streams/issues/events{/number}","events_url":"https://api.github.com/repos/ncloudioj/activity-streams/events","assignees_url":"https://api.github.com/repos/ncloudioj/activity-streams/assignees{/user}","branches_url":"https://api.github.com/repos/ncloudioj/activity-streams/branches{/branch}","tags_url":"https://api.github.com/repos/ncloudioj/activity-streams/tags","blobs_url":"https://api.github.com/repos/ncloudioj/activity-streams/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ncloudioj/activity-streams/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ncloudioj/activity-streams/git/refs{/sha}","trees_url":"https://api.github.com/repos/ncloudioj/activity-streams/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ncloudioj/activity-streams/statuses/{sha}","languages_url":"https://api.github.com/repos/ncloudioj/activity-streams/languages","stargazers_url":"https://api.github.com/repos/ncloudioj/activity-streams/stargazers","contributors_url":"https://api.github.com/repos/ncloudioj/activity-streams/contributors","subscribers_url":"https://api.github.com/repos/ncloudioj/activity-streams/subscribers","subscription_url":"https://api.github.com/repos/ncloudioj/activity-streams/subscription","commits_url":"https://api.github.com/repos/ncloudioj/activity-streams/commits{/sha}","git_commits_url":"https://api.github.com/repos/ncloudioj/activity-streams/git/commits{/sha}","comments_url":"https://api.github.com/repos/ncloudioj/activity-streams/comments{/number}","issue_comment_url":"https://api.github.com/repos/ncloudioj/activity-streams/issues/comments{/number}","contents_url":"https://api.github.com/repos/ncloudioj/activity-streams/contents/{+path}","compare_url":"https://api.github.com/repos/ncloudioj/activity-streams/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ncloudioj/activity-streams/merges","archive_url":"https://api.github.com/repos/ncloudioj/activity-streams/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ncloudioj/activity-streams/downloads","issues_url":"https://api.github.com/repos/ncloudioj/activity-streams/issues{/number}","pulls_url":"https://api.github.com/repos/ncloudioj/activity-streams/pulls{/number}","milestones_url":"https://api.github.com/repos/ncloudioj/activity-streams/milestones{/number}","notifications_url":"https://api.github.com/repos/ncloudioj/activity-streams/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ncloudioj/activity-streams/labels{/name}","releases_url":"https://api.github.com/repos/ncloudioj/activity-streams/releases{/id}","deployments_url":"https://api.github.com/repos/ncloudioj/activity-streams/deployments","created_at":"2016-04-04T15:02:16Z","updated_at":"2016-04-04T15:02:17Z","pushed_at":"2016-09-06T18:16:37Z","git_url":"git://github.com/ncloudioj/activity-streams.git","ssh_url":"git@github.com:ncloudioj/activity-streams.git","clone_url":"https://github.com/ncloudioj/activity-streams.git","svn_url":"https://github.com/ncloudioj/activity-streams","homepage":"","size":1939,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","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":"mozilla:master","ref":"master","sha":"c6564c4b513617a3fb86ca40fe800ed92d215162","user":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"repo":{"id":50695589,"name":"activity-stream","full_name":"mozilla/activity-stream","owner":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla/activity-stream","description":" MVP prototype add-on for activity streams","fork":false,"url":"https://api.github.com/repos/mozilla/activity-stream","forks_url":"https://api.github.com/repos/mozilla/activity-stream/forks","keys_url":"https://api.github.com/repos/mozilla/activity-stream/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla/activity-stream/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla/activity-stream/teams","hooks_url":"https://api.github.com/repos/mozilla/activity-stream/hooks","issue_events_url":"https://api.github.com/repos/mozilla/activity-stream/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla/activity-stream/events","assignees_url":"https://api.github.com/repos/mozilla/activity-stream/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla/activity-stream/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla/activity-stream/tags","blobs_url":"https://api.github.com/repos/mozilla/activity-stream/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla/activity-stream/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla/activity-stream/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla/activity-stream/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla/activity-stream/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla/activity-stream/languages","stargazers_url":"https://api.github.com/repos/mozilla/activity-stream/stargazers","contributors_url":"https://api.github.com/repos/mozilla/activity-stream/contributors","subscribers_url":"https://api.github.com/repos/mozilla/activity-stream/subscribers","subscription_url":"https://api.github.com/repos/mozilla/activity-stream/subscription","commits_url":"https://api.github.com/repos/mozilla/activity-stream/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla/activity-stream/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla/activity-stream/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla/activity-stream/issues/comments{/number}","contents_url":"https://api.github.com/repos/mozilla/activity-stream/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla/activity-stream/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla/activity-stream/merges","archive_url":"https://api.github.com/repos/mozilla/activity-stream/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla/activity-stream/downloads","issues_url":"https://api.github.com/repos/mozilla/activity-stream/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla/activity-stream/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla/activity-stream/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla/activity-stream/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla/activity-stream/labels{/name}","releases_url":"https://api.github.com/repos/mozilla/activity-stream/releases{/id}","deployments_url":"https://api.github.com/repos/mozilla/activity-stream/deployments","created_at":"2016-01-29T22:28:26Z","updated_at":"2016-09-01T04:51:13Z","pushed_at":"2016-09-06T21:14:39Z","git_url":"git://github.com/mozilla/activity-stream.git","ssh_url":"git@github.com:mozilla/activity-stream.git","clone_url":"https://github.com/mozilla/activity-stream.git","svn_url":"https://github.com/mozilla/activity-stream","homepage":"","size":2497,"stargazers_count":57,"watchers_count":57,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":34,"mirror_url":null,"open_issues_count":174,"forks":34,"open_issues":174,"watchers":57,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mozilla/activity-stream/pulls/1209"},"html":{"href":"https://github.com/mozilla/activity-stream/pull/1209"},"issue":{"href":"https://api.github.com/repos/mozilla/activity-stream/issues/1209"},"comments":{"href":"https://api.github.com/repos/mozilla/activity-stream/issues/1209/comments"},"review_comments":{"href":"https://api.github.com/repos/mozilla/activity-stream/pulls/1209/comments"},"review_comment":{"href":"https://api.github.com/repos/mozilla/activity-stream/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mozilla/activity-stream/pulls/1209/commits"},"statuses":{"href":"https://api.github.com/repos/mozilla/activity-stream/statuses/746cc964779337934ccf17c46cb1c2fc06cf981c"}}}}
{"actor":{"display_login":"dmose"}}