From 74bbdb46cc0fb6b44e658cd87c7b09b0ec1afb24 Mon Sep 17 00:00:00 2001 From: deepsweet Date: Fri, 14 Dec 2012 05:56:24 +0400 Subject: [PATCH] lib/svgo: store elapsed time in result object --- examples/fromFile.js | 28 ++++++++++++++++------------ examples/fromStream.js | 28 ++++++++++++++++------------ examples/fromString.js | 28 ++++++++++++++++------------ lib/svgo.js | 4 ++++ 4 files changed, 52 insertions(+), 36 deletions(-) diff --git a/examples/fromFile.js b/examples/fromFile.js index 1565afe1..8f1fb720 100644 --- a/examples/fromFile.js +++ b/examples/fromFile.js @@ -10,18 +10,22 @@ svgo .then(function(result) { console.log(result); - // output: - // { - // // optimized SVG data string - // data: 'test' - // // 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: 'test' + // 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 diff --git a/examples/fromStream.js b/examples/fromStream.js index 4840163e..e332e97e 100644 --- a/examples/fromStream.js +++ b/examples/fromStream.js @@ -15,18 +15,22 @@ svgo .then(function(result) { console.log(result); - // output: - // { - // // optimized SVG data string - // data: 'test' - // // 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: 'test' + // 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 diff --git a/examples/fromString.js b/examples/fromString.js index 1c371090..2c7e48c9 100644 --- a/examples/fromString.js +++ b/examples/fromString.js @@ -10,18 +10,22 @@ svgo .then(function(result) { console.log(result); - // output: - // { - // // optimized SVG data string - // data: 'test' - // // 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: 'test' + // 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 diff --git a/lib/svgo.js b/lib/svgo.js index 8a9db98b..845671fa 100644 --- a/lib/svgo.js +++ b/lib/svgo.js @@ -48,6 +48,8 @@ module.exports = INHERIT(/** @lends SVGO.prototype */{ */ fromString: function(str) { + var startTime = Date.now(); + str = decodeSVGDatauri(str); return this.config @@ -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; });