Skip to content

Commit

Permalink
refactor: Fix benchmarks to use latest APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed Apr 11, 2016
1 parent 888922a commit a170f98
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
19 changes: 9 additions & 10 deletions benchmarks/mongodb.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/// <reference path="../typings/DefinitelyTyped/tsd.d.ts" />
import Iridium = require("../index");
import Bluebird = require("bluebird");
import MongoDB = require("mongodb");
Expand Down Expand Up @@ -52,11 +51,11 @@ function benchmark(name: string, prepare: (objects: UserDocument[]) => Bluebird<
return time;
});
})
}, { concurency: 1 }).then(times => {
}, { concurrency: 1 }).then(times => {
results[name] = _.reduce(<number[]><any>times,(x, y) => x + y, 0) / times.length;
console.log("%s: %dms", name, results[name]);
if (compareTo) {
if (Math.abs(results[name] - results[compareTo]) / results[compareTo] < 0.1);
if (Math.abs(results[name] - results[compareTo]) / results[compareTo] < 0.1) { }
else if (results[name] > results[compareTo]) console.log(" - %dx slower than %s",(results[name] / results[compareTo]).toPrecision(2), compareTo);
else if (results[name] < results[compareTo]) console.log(" - %dx faster than %s",(results[name] / results[compareTo]).toPrecision(2), compareTo);
}
Expand All @@ -71,22 +70,22 @@ iDB.connect()
.then(() => iDB.UserWrapped.remove())
.then(() => {
return new Bluebird<any>((resolve, reject) => {
iDB.connection.collection("mongodb").remove((err) => {
iDB.connection.collection("mongodb").deleteMany((err) => {
if (err) return reject(err);
return resolve(null);
});
});
})
.then(() => benchmark("MongoDB insert()",() => {
return new Bluebird((resolve, reject) => {
iDB.connection.collection("mongodb").remove({},(err) => {
iDB.connection.collection("mongodb").deleteMany({},(err) => {
if (err) return reject(err);
return resolve(null);
});
});
},(objects) => {
return new Bluebird<any>((resolve, reject) => {
iDB.connection.collection("mongodb").insert(objects,(err, objects) => {
iDB.connection.collection("mongodb").insertMany(objects,(err, objects) => {
if (err) return reject(err);
return resolve(objects);
});
Expand All @@ -97,7 +96,7 @@ iDB.connect()

.then(() => benchmark("MongoDB find()",() => null,() => {
return new Bluebird<any>((resolve, reject) => {
iDB.connection.collection("mongodb").find().toArray((err, objects: any) => {
iDB.connection.collection("mongodb").find({}).toArray((err, objects: any) => {
if (err) return reject(err);
return resolve(objects);
});
Expand All @@ -108,22 +107,22 @@ iDB.connect()

.then(() => {
return new Bluebird<any>((resolve, reject) => {
iDB.connection.collection("mongodb").remove((err, objects: any) => {
iDB.connection.collection("mongodb").deleteMany((err, objects: any) => {
if (err) return reject(err);
return resolve(objects);
});
});
})
.then(() => benchmark("MongoDB remove()",(objects) => {
return new Bluebird<any>((resolve, reject) => {
iDB.connection.collection("mongodb").insert(objects,(err, objects) => {
iDB.connection.collection("mongodb").deleteMany(objects,(err, objects) => {
if (err) return reject(err);
return resolve(objects);
});
});
},() => {
return new Bluebird<any>((resolve, reject) => {
iDB.connection.collection("mongodb").remove((err, objects: any) => {
iDB.connection.collection("mongodb").deleteMany((err, objects: any) => {
if (err) return reject(err);
return resolve(objects);
});
Expand Down
10 changes: 0 additions & 10 deletions benchmarks/tsconfig.json

This file was deleted.

0 comments on commit a170f98

Please sign in to comment.