Last active
November 27, 2016 10:48
-
-
Save the-codepunker/ce555f6c874592111ebf5dd2a3e71460 to your computer and use it in GitHub Desktop.
node and such
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DESC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var spinner = require("char-spinner"); | |
var async = require("async"); | |
spinner(); | |
var dataSize = 100000; | |
//uncomment below as needed | |
async.series([ | |
/* == INSERT == */ | |
/* function(callback){ | |
require('./mysql')('insert',dataSize,callback); | |
}, | |
function(callback){ | |
require('./mongo')('insert',dataSize,callback); | |
},*/ | |
/* == SELECT == */ | |
/* function(callback){ | |
require('./mysql')('find',dataSize,callback); | |
},*/ | |
/*function(callback){ | |
require('./mongo')('find',dataSize,callback); | |
}*/ | |
function(callback){ | |
require('./mongo')('findwithlookup',dataSize,callback); | |
} | |
],function(){ | |
process.exit(); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var async = require('async'); | |
var faker = require('Faker'); | |
var mongojs = require('mongojs'); | |
var db = mongojs('test',["test","team"]); | |
var self = {}; | |
self.insert = function(dataSize,done){ | |
var run = []; | |
run.push(function(callback){ | |
db.test.remove({},callback); | |
}) | |
run.push(function(callback){ | |
db.team.remove({},callback); | |
}) | |
run.push(function(callback){ | |
db.team.createIndex({id:1},callback); | |
}); | |
run.push(function(callback){ | |
db.test.createIndex({team:1},callback); | |
}); | |
for(var i=0;i<dataSize;i++){ | |
run.push(function(callback){ | |
db.test.insert({ | |
player:faker.Name.findName(), | |
email:faker.Internet.email(), | |
score:Math.floor(Math.random()*1000), | |
team:Math.floor(Math.random()*dataSize), | |
},callback); | |
}); | |
run.push(function(callback){ | |
db.team.count({},function(err,data){ | |
db.team.insert({ | |
city:faker.Address.city(), | |
country:faker.Address.ukCountry(), | |
id:data, | |
name:faker.Company.companyName().split(" ")[0].split(",")[0] | |
},callback); | |
}) | |
}); | |
} | |
console.time('mongo insert'); | |
async.series(run,function(err,data){ | |
// console.log(err); | |
console.timeEnd('mongo insert'); | |
if(done) done(); | |
}); | |
} | |
self.find = function(dataSize,done){ | |
var run = []; | |
console.time('mongo select'); | |
db.test.find({},function(err,data){ | |
data.forEach(function(player){ | |
run.push(function(callback){ | |
db.team.find({id:player.team},function(err,data){ | |
if(!data[0].name) console.log('mongo error : team no name'); | |
console.log(data[0].name); | |
callback(); | |
}) | |
}); | |
}); | |
async.series(run,function(err,data){ | |
// console.log(err); | |
if(done) { | |
console.timeEnd('mongo select'); | |
done(); | |
} | |
}); | |
}); | |
} | |
self.findwithlookup = function(dataSize,done){ | |
var run = []; | |
console.time('mongo select'); | |
var a = db.test.aggregate([ | |
{ | |
$lookup: | |
{ | |
from: "team", | |
localField: "team", | |
foreignField: "id", | |
as: "joined_document" | |
} | |
} | |
]); | |
a.on('data', function(data){ | |
console.log(data.joined_document[0].name); | |
}); | |
a.on('end', function() { | |
console.timeEnd('mongo select'); | |
}); | |
} | |
module.exports = function(type,dataSize,done){ | |
return self[type](dataSize,done); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "none", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"author": "Daniel G", | |
"license": "MIT", | |
"dependencies": { | |
"Faker": "^0.7.2", | |
"async": "^1.4.2", | |
"char-spinner": "^1.0.1", | |
"mongojs": "^1.3.0", | |
"mq-node": "^1.0.1-2" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$start = microtime(TRUE); | |
$db = new mysqli("localhost", "danielgr_user", "EhVyHU#LL,_+", "w3b"); | |
$res = $db->query("SELECT `player`, `name` FROM test as t1 inner join team as t2 on t2.id=t1.team"); | |
while ($row = $res->fetch_object()) { | |
echo $row->name; | |
} | |
$time = microtime(true)-$start; | |
echo "Time: " . $time . PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment