Skip to content

Instantly share code, notes, and snippets.

@thecaddy
Created June 17, 2015 22:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thecaddy/beb959ccfdb5a298deae to your computer and use it in GitHub Desktop.
Save thecaddy/beb959ccfdb5a298deae to your computer and use it in GitHub Desktop.
Dedupe Perf Test
//PUT YOUR SHIT HERE
//var detectDupes = require('YOUR JUNK IN THE TRUNK');
var chai = require('chai');
var expect = chai.expect;
var moment = require('moment');
var _ = require('lodash-node');
describe('Order Dup Test', function(){
var order = {
orderId: '23084ldskjf',
orderDate: moment().toISOString(),
shippingState: 'WA',
shippingZip: '98101',
shipping: 30.00,
shippingTax: 1.00
}
it('should have no dupes', function(done) {
var testOrder = _.extend({}, order);
testOrder.shippingTax = Math.random().toString();
var testOrder2 = _.extend({}, order);
testOrder2.orderId = Math.random().toString();
var testOrder3 = _.extend({}, order);
testOrder3.orderId = Math.random().toString();
var dupes = detectDupes([
testOrder,
testOrder2,
testOrder3
]);
expect(dupes).to.be.empty;
done();
});
it('should process duplicate orders', function(done){
var testOrder = _.extend({}, order);
testOrder.orderId = Math.random().toString();
testOrder.shippingTax = '.00';
var testOrder2 = _.extend({}, order);
testOrder2.orderId = Math.random().toString();
var testOrder3 = _.extend({}, order);
testOrder3.orderId = Math.random().toString();
var dupes = detectDupes([testOrder, testOrder, testOrder,
testOrder2, testOrder2, testOrder3]);
expect(dupes[testOrder.orderId]).to.equal(3);
expect(dupes[testOrder2.orderId]).to.equal(2);
expect(dupes[testOrder3]).to.be.undefined;
done();
});
it('should process duplicate orders with same id', function(done){
var testOrder = _.extend({}, order);
testOrder.shippingTax = '.00';
var testOrder2 = _.extend({}, order);
testOrder2.shippingTax = Math.random().toString();
var testOrder3 = _.extend({}, order);
testOrder3.shippingTax = Math.random().toString();
var dupes = detectDupes([testOrder, testOrder, testOrder,
testOrder2, testOrder2, testOrder3]);
expect(dupes[testOrder.orderId]).to.equal(3);
done();
});
[1000,10000,100000,1000000].forEach(function(item, index){
it('should process ' + item + ' duplicate orders', function(done) {
var testOrder = _.extend({}, order);
testOrder.orderId = Math.random().toString();
var testArr = []
for(var i = 0, len = item; i < len; i++){
testArr.push(testOrder);
}
var start = moment();
var dupes = detectDupes(testArr);
var ms = moment.duration(moment().diff(start)).asMilliseconds();
expect(dupes[testOrder.orderId]).to.be.ok;
expect(dupes[testOrder.orderId]).to.equal(item);
console.log('TOOK: ' + ms + 'ms');
done();
});
})
})
@jerational
Copy link

|_| on chin

@marcus
Copy link

marcus commented Jun 18, 2015

It's okay you think you winnin'
wit' that icy code you spinnin'

@marcus
Copy link

marcus commented Jun 18, 2015

These tests are.... ................... 😵

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment