Last active
August 29, 2015 14:16
-
-
Save dmarcelino/758f4ff4629bb9bf3a42 to your computer and use it in GitHub Desktop.
Decoding OrientDB RID: decodeURIComponent vs string.replace
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 n = 5000000; | |
var encodedRid = '%2310%3A23'; // #10:23 | |
console.time('decodeURIComponent 1/2'); | |
for (var i = 0; i < n; i++) { | |
decodeURIComponent(encodedRid); | |
} | |
console.timeEnd('decodeURIComponent 1/2'); | |
console.time('str.replace 1/2'); | |
for (var i = 0; i < n; i++) { | |
var res = encodedRid.replace('%23', '#'); | |
res.replace('%3A', ':'); | |
} | |
console.timeEnd('str.replace 1/2'); | |
console.time('str.replace regex 1/2'); | |
for (var i = 0; i < n; i++) { | |
var res = encodedRid.replace(/%23/, '#'); | |
res.replace(/%3A/, ':'); | |
} | |
console.timeEnd('str.replace regex 1/2'); | |
console.time('str.replace regex 2/2'); | |
for (var i = 0; i < n; i++) { | |
var res = encodedRid.replace(/%23/, '#'); | |
res.replace(/%3A/, ':'); | |
} | |
console.timeEnd('str.replace regex 2/2'); | |
console.time('str.replace 2/2'); | |
for (var i = 0; i < n; i++) { | |
var res = encodedRid.replace('%23', '#'); | |
res.replace('%3A', ':'); | |
} | |
console.timeEnd('str.replace 2/2'); | |
console.time('decodeURIComponent 2/2'); | |
for (var i = 0; i < n; i++) { | |
decodeURIComponent(encodedRid); | |
} | |
console.timeEnd('decodeURIComponent 2/2'); | |
/* | |
decodeURIComponent 1/2: 1503ms | |
str.replace 1/2: 1226ms | |
str.replace regex 1/2: 2482ms | |
str.replace regex 2/2: 2499ms | |
str.replace 2/2: 1215ms | |
decodeURIComponent 2/2: 1506ms | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment