Created
July 26, 2012 08:46
-
-
Save schamane/3181047 to your computer and use it in GitHub Desktop.
premature optimization
This file contains hidden or 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 pool = { | |
query: function(sql, callback) { | |
process.nextTick(function() { | |
var result = [ | |
{0:12345, 1:'EUR/USD', 2:1.2234, 3:1.2221, 4:1.2240, length: 5}, | |
{0:12345, 1:'EUR/USD', 2:1.2234, 3:1.2221, 4:1.2240, length: 5 }, | |
{0:12345, 1:'EUR/USD', 2:1.2234, 3:1.2221, 4:1.2240, length: 5}] | |
callback(null, result); | |
}); | |
} | |
}; | |
function castArray(result) { | |
var len = result.length, arr = [], x; | |
for (x = 0; x < len; x += 1) { | |
arr[x] = Array.prototype.slice.call(result[x]); | |
}; | |
return arr; | |
} | |
var start1 = process.hrtime(); | |
pool.query('SELECT id AS `0`, symbol AS `1`, price AS `2`, bid AS `3`, ask AS `4`, 5 AS `length` FROM session_quotes', function (error, result) { | |
if (error) { | |
console.log(error); | |
return; | |
}; | |
result = castArray(result); | |
console.log("time:" + process.hrtime(start1)); | |
console.log(result); | |
}); |
This file contains hidden or 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 pool = { | |
query: function(sql, callback) { | |
process.nextTick(function() { | |
var result = [ | |
{id:12345, symbol:'EUR/USD', price:1.2234, bid:1.2221, ask:1.2240}, | |
{id:12345, symbol:'EUR/USD', price:1.2234, bid:1.2221, ask:1.2240 }, | |
{id:12345, symbol:'EUR/USD', price:1.2234, bid:1.2221, ask:1.2240}] | |
callback(null, result); | |
}); | |
} | |
}; | |
var start1 = process.hrtime(); | |
pool.query('SELECT id, symbol, price, bid, ask FROM session_quotes', function (error, result) { | |
if (error) { | |
console.log(error); | |
return; | |
}; | |
console.log("time:" + process.hrtime(start1)); | |
console.log(result); | |
}); |
Он не нужен, но и не мешает. Просто для симуляции ответа от базы данных.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
а зачем нужен тут nextTick?