mirror of
https://github.com/sstent/node.git
synced 2026-01-26 07:02:31 +00:00
first post
This commit is contained in:
42
Nodejs-Socketio-Mysql-Demo/node_modules/mysql/benchmark/node-mysql/insert.js
generated
vendored
Normal file
42
Nodejs-Socketio-Mysql-Demo/node_modules/mysql/benchmark/node-mysql/insert.js
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
require('../../test/common');
|
||||
var Client = require('mysql/client'),
|
||||
client = Client(TEST_CONFIG);
|
||||
|
||||
client.connect();
|
||||
|
||||
client.query('CREATE DATABASE '+TEST_DB, function(err) {
|
||||
if (err && err.number != Client.ERROR_DB_CREATE_EXISTS) {
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
client.query('USE '+TEST_DB);
|
||||
client.query('DROP TABLE IF EXISTS '+TEST_TABLE);
|
||||
client.query(
|
||||
'CREATE TABLE '+TEST_TABLE+' ('+
|
||||
'id INT(11) AUTO_INCREMENT, '+
|
||||
'title VARCHAR(255), '+
|
||||
'text TEXT, '+
|
||||
'created DATETIME, '+
|
||||
'PRIMARY KEY (id));',
|
||||
function(err) {
|
||||
if (err) throw err;
|
||||
|
||||
var start = +new Date, inserts = 0, total = 10000;
|
||||
function insertOne() {
|
||||
client.query('INSERT INTO '+TEST_TABLE+' SET title = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"', function() {
|
||||
inserts++;
|
||||
if (inserts < total) {
|
||||
insertOne();
|
||||
} else {
|
||||
var duration = (+new Date - start) / 1000,
|
||||
insertsPerSecond = inserts / duration;
|
||||
|
||||
console.log('%d inserts / second', insertsPerSecond.toFixed(2));
|
||||
console.log('%d ms', +new Date - start);
|
||||
client.end();
|
||||
}
|
||||
});
|
||||
}
|
||||
insertOne();
|
||||
}
|
||||
);
|
||||
39
Nodejs-Socketio-Mysql-Demo/node_modules/mysql/benchmark/node-mysql/select.js
generated
vendored
Normal file
39
Nodejs-Socketio-Mysql-Demo/node_modules/mysql/benchmark/node-mysql/select.js
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
// Last v8 profile when running this test for 500k rows:
|
||||
// https://gist.github.com/f85c38010c038e5efe2e
|
||||
var common = require('../../test/common');
|
||||
var Client = require('../../lib/client'),
|
||||
client = common.createClient(),
|
||||
rows = 0;
|
||||
|
||||
client.typeCast = false;
|
||||
|
||||
client.query('CREATE DATABASE '+common.TEST_DB, function(err) {
|
||||
//if (err && err.number != Client.ERROR_DB_CREATE_EXISTS) {
|
||||
//throw err;
|
||||
//}
|
||||
});
|
||||
|
||||
client.query('USE '+common.TEST_DB);
|
||||
var selectStart = +new Date;
|
||||
|
||||
function query() {
|
||||
client
|
||||
.query('SELECT * FROM '+common.TEST_TABLE)
|
||||
.on('row', function(row) {
|
||||
rows++;
|
||||
})
|
||||
.on('end', function() {
|
||||
if (rows < 10000) {
|
||||
query();
|
||||
return;
|
||||
}
|
||||
|
||||
var duration = (+new Date - selectStart) / 1000,
|
||||
rowsPerSecond = rows / duration;
|
||||
console.log('%d rows / second', rowsPerSecond.toFixed(2));
|
||||
console.log('%d ms', +new Date - selectStart);
|
||||
client.end();
|
||||
});
|
||||
}
|
||||
|
||||
query();
|
||||
40
Nodejs-Socketio-Mysql-Demo/node_modules/mysql/benchmark/php/insert-select.php
generated
vendored
Normal file
40
Nodejs-Socketio-Mysql-Demo/node_modules/mysql/benchmark/php/insert-select.php
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
$INSERTS = 10000;
|
||||
|
||||
$config = array(
|
||||
'host' => 'localhost',
|
||||
'port' => 3306,
|
||||
'user' => 'root',
|
||||
'password' => 'root',
|
||||
'db' => 'node_mysql_test',
|
||||
'table' => 'post',
|
||||
);
|
||||
extract($config);
|
||||
|
||||
$connection = mysql_connect($host, $user, $password);
|
||||
mysql_query('USE '.$db, $connection);
|
||||
mysql_query('CREATE TEMPORARY TABLE '.$table.' ('.
|
||||
'id INT(11) AUTO_INCREMENT, '.
|
||||
'title VARCHAR(255), '.
|
||||
'text TEXT, '.
|
||||
'created DATETIME, '.
|
||||
'PRIMARY KEY (id));', $connection);
|
||||
|
||||
$start = microtime(true);
|
||||
for ($i = 0; $i < $INSERTS; $i++) {
|
||||
mysql_query('INSERT INTO '.$table.' SET title = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";', $connection);
|
||||
}
|
||||
$duration = (microtime(true) - $start);
|
||||
$insertsPerSecond = $INSERTS / $duration;
|
||||
echo sprintf("%d inserts / second\n", $insertsPerSecond);
|
||||
echo sprintf("%d ms\n", $duration * 1000);
|
||||
|
||||
$start = microtime(true);
|
||||
$q = mysql_query('SELECT * FROM '.$table);
|
||||
while ($a = mysql_fetch_assoc($q)) {
|
||||
}
|
||||
$duration = (microtime(true) - $start);
|
||||
$rowsPerSecond = $INSERTS / $duration;
|
||||
echo sprintf("%d rows / second\n", $rowsPerSecond);
|
||||
echo sprintf("%d ms\n", $duration * 1000);
|
||||
?>
|
||||
Reference in New Issue
Block a user