-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #555 from benesch/custom-type-coercion
Supercharge `prepareValue`
- Loading branch information
Showing
4 changed files
with
220 additions
and
31 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
var utils = require("../lib/utils"); | ||
|
||
var numArr = []; | ||
for (var i = 0; i < 1000; i++) numArr[i] = i; | ||
console.time("prepare-number-array"); | ||
for (var i = 0; i < 100; i++) { | ||
utils.prepareValue(numArr); | ||
} | ||
console.timeEnd("prepare-number-array"); | ||
|
||
|
||
var strArr = new Array(10000); | ||
console.time("prepare-string-array"); | ||
for (var i = 0; i < 100; i++) { | ||
utils.prepareValue(strArr); | ||
} | ||
console.timeEnd("prepare-string-array"); | ||
|
||
|
||
var objArr = []; | ||
for (var i = 0; i < 1000; i++) objArr[i] = { x: { y: 42 }}; | ||
console.time("prepare-object-array"); | ||
for (var i = 0; i < 100; i++) { | ||
utils.prepareValue(objArr); | ||
} | ||
console.timeEnd("prepare-object-array"); | ||
|
||
|
||
var obj = { x: { y: 42 }}; | ||
console.time("prepare-object"); | ||
for (var i = 0; i < 100000; i++) { | ||
utils.prepareValue(obj); | ||
} | ||
console.timeEnd("prepare-object"); | ||
|
||
|
||
var customType = { | ||
toPostgres: function () { | ||
return { toPostgres: function () { return new Date(); } }; | ||
} | ||
}; | ||
console.time("prepare-custom-type"); | ||
for (var i = 0; i < 100000; i++) { | ||
utils.prepareValue(customType); | ||
} | ||
console.timeEnd("prepare-custom-type"); |
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
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
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