Skip to content

Commit 2bb907e

Browse files
author
Thomas Rueckstiess
committed
calculate avgTimePerDoc
1 parent 61ab6db commit 2bb907e

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/models/sampled-schema.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ var metrics = {
1717
err = null;
1818
}
1919
if (err) {
20-
debugMetrics('metrics error: ', err, obj);
20+
debugMetrics(label, err, obj);
2121
} else {
22-
debugMetrics('metrics log: ', obj);
22+
debugMetrics(label, obj);
2323
}
2424
}
2525
};
@@ -123,7 +123,6 @@ module.exports = Schema.extend({
123123
};
124124
var start = new Date();
125125
var timeAtFirstDoc;
126-
var avgTimePerDoc = 0;
127126
var erroredOnDocs = [];
128127

129128
// No results found
@@ -144,7 +143,6 @@ module.exports = Schema.extend({
144143
if (!timeAtFirstDoc) {
145144
timeAtFirstDoc = new Date();
146145
}
147-
var timePerDoc = new Date();
148146
try {
149147
model.parse(doc);
150148
} catch (err) {
@@ -154,9 +152,6 @@ module.exports = Schema.extend({
154152
schema: model.serialize()
155153
});
156154
}
157-
timePerDoc = new Date() - timePerDoc;
158-
avgTimePerDoc += timePerDoc;
159-
debug('avg time', timePerDoc);
160155
cb(null, doc);
161156
};
162157

@@ -172,13 +167,16 @@ module.exports = Schema.extend({
172167
model.documents.trigger('sync');
173168

174169
// @note (imlucas): Any other metrics? Feedback on `Schema *`?
170+
var totalTime = new Date() - start;
171+
var timeToFirstDoc = timeAtFirstDoc - start;
172+
175173
metrics.track('Schema: Complete', {
176-
Duration: new Date() - start,
174+
Duration: totalTime,
177175
'Total Document Count': model.total,
178176
'Sample Size': model.documents.length,
179177
'Errored Document Count': erroredOnDocs.length,
180-
'Time to First Doc': timeAtFirstDoc - start,
181-
'Average Time Per Doc': avgTimePerDoc / model.documents.length
178+
'Time to First Doc': timeToFirstDoc,
179+
'Average Time Per Doc': (totalTime - timeToFirstDoc) / model.documents.length
182180
// 'Schema Height': model.height, // # of top level keys
183181
// 'Schema Width': model.width, // max nesting depth
184182
// 'Schema Sparsity': model.sparsity // lots of fields missing or consistent

0 commit comments

Comments
 (0)