Skip to content

Commit

Permalink
lib/svgo: store elapsed time in result object
Browse files Browse the repository at this point in the history
  • Loading branch information
deepsweet committed Dec 17, 2012
1 parent 0229a40 commit 74bbdb4
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 36 deletions.
28 changes: 16 additions & 12 deletions examples/fromFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,22 @@ svgo
.then(function(result) {

console.log(result);
// output:
// {
// // optimized SVG data string
// data: '<svg width="10" height="20">test</svg>'
// // additional info such as width/height and start/end bytes length
// info: {
// width: '10',
// height: '20',
// inBytes: 59,
// outBytes: 38
// }
// }
/*
output:
{
// optimized SVG data string
data: '<svg width="10" height="20">test</svg>'
// additional info such as width/height and start/end bytes length
info: {
width: '10',
height: '20',
inBytes: 59,
outBytes: 38,
time: N
}
}
*/

})
// end promises chain
Expand Down
28 changes: 16 additions & 12 deletions examples/fromStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,22 @@ svgo
.then(function(result) {

console.log(result);
// output:
// {
// // optimized SVG data string
// data: '<svg width="10" height="20">test</svg>'
// // additional info such as width/height and start/end bytes length
// info: {
// width: '10',
// height: '20',
// inBytes: 59,
// outBytes: 38
// }
// }
/*
output:
{
// optimized SVG data string
data: '<svg width="10" height="20">test</svg>'
// additional info such as width/height and start/end bytes length
info: {
width: '10',
height: '20',
inBytes: 59,
outBytes: 38,
time: N
}
}
*/

})
// end promises chain
Expand Down
28 changes: 16 additions & 12 deletions examples/fromString.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,22 @@ svgo
.then(function(result) {

console.log(result);
// output:
// {
// // optimized SVG data string
// data: '<svg width="10" height="20">test</svg>'
// // additional info such as width/height and start/end bytes length
// info: {
// width: '10',
// height: '20',
// inBytes: 52,
// outBytes: 38
// }
// }
/*
output:
{
// optimized SVG data string
data: '<svg width="10" height="20">test</svg>'
// additional info such as width/height and start/end bytes length
info: {
width: '10',
height: '20',
inBytes: 52,
outBytes: 38,
time: N
}
}
*/

})
// end promises chain
Expand Down
4 changes: 4 additions & 0 deletions lib/svgo.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ module.exports = INHERIT(/** @lends SVGO.prototype */{
*/
fromString: function(str) {

var startTime = Date.now();

str = decodeSVGDatauri(str);

return this.config
Expand All @@ -61,6 +63,8 @@ module.exports = INHERIT(/** @lends SVGO.prototype */{
result.info.inBytes = Buffer.byteLength(str, 'utf-8');
result.info.outBytes = Buffer.byteLength(result.data, 'utf-8');

result.info.time = Date.now() - startTime;

return result;

});
Expand Down

0 comments on commit 74bbdb4

Please sign in to comment.