Skip to content

Commit

Permalink
Round duration for measures to nearest ms (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
querymetrics authored and nicjansma committed Sep 15, 2016
1 parent e06b944 commit 2e13055
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# usertiming-compression.js

v0.1.3
v0.1.4

[http://nicj.net](http://nicj.net)

Expand Down Expand Up @@ -205,6 +205,7 @@ Or via ``gulp``:
* v0.1.1 - 2016-04-04: `getCompressedUserTiming()` gathers Measures that end after the specified `from`
* v0.1.2 - 2016-04-04: Protect against X-O frame access that crashes some browsers
* v0.1.3 - 2016-07-25: `getCompressedUserTiming()` accepts an alternate window param passed into options
* v0.1.4 - 2016-08-10: Round `duration` values on Measures to nearest millisecond

## Thanks

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "usertiming-compression",
"version": "0.1.3",
"version": "0.1.4",
"homepage": "https://github.com/nicjansma/usertiming-compression.js",
"authors": [
"Nic Jansma <[email protected]>"
Expand Down
2 changes: 1 addition & 1 deletion dist/usertiming-compression.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "UserTiming compression and decompression",
"main": "./src/usertiming-compression",
"author": "Nic Jansma",
"version": "0.1.3",
"version": "0.1.4",
"repository": {
"type": "git",
"url": "http://github.com/nicjansma/usertiming-compression.js.git"
Expand Down
5 changes: 3 additions & 2 deletions src/usertiming-compression.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,9 @@
var finalValue = time;

// if this is a measure (with a duration), tack on "_[duration]"
if (typeof value.duration !== "undefined") {
var duration = self.toBase36(value.duration);
if (typeof value.duration === "number") {
// round duration to nearest ms
var duration = self.toBase36(Math.round(value.duration));

finalValue += "_";

Expand Down
9 changes: 9 additions & 0 deletions test/test-usertiming-compression.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@
}])).to.deep.equal({"measure1": "1_1"});
});

it("should compress a single measure with a rounded duration", function() {
expect(utc.compressUserTiming([{
entryType: "measure",
name: "measure1",
startTime: 1,
duration: 0.750
}])).to.deep.equal({"measure1": "1_1"});
});

it("should compress a single measure with a duration of 0", function() {
expect(utc.compressUserTiming([{
entryType: "measure",
Expand Down

0 comments on commit 2e13055

Please sign in to comment.