jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
Testing optimization for the parseJSON function
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
$.noConflict();
var json = '{ "Datasets" : [ { "dsid" : 9, "name" : "asetsry_cb01", "description" : "Cwryrwhdntndttdjytdkdtikdtikdtikdt", "wet" : "-17.5512465374,-0.0000000327,51.4670360111,16.0066496164", "jtest_wet" : "-17.5512465374,-0.0000000327,51.4670360111,16.0066496164" }, { "dsid" : 7, "name" : "afritydkdtykdytkcom_cb05", "description" : "srsryrshasdustrjdyrjstjstrj", "wet" : "-17.6260387812,-35.0102301714,51.4819944598,37.6342710921", "jtest_wet" : "-17.6260387812,-35.0102301714,51.4819944598,37.6342710921" }, { "dsid" : 4, "name" : "africkydtkdytkom_ktycdrg", "description" : "kydkdykdtykdytkdtyM", "wet" : "-180.0000000000,-86.9695423663,198.9473684211,86.9695423663", "jtest_wet" : "-180.0000000000,-86.9695423663,198.9473684211,86.9695423663" }, { "dsid" : 8, "name" : "africodtykdytkm_dted", "description" : "DdkydkdtykytdkytdkM", "wet" : "yesrutjutsrngnklgklmndgklngx klng lkndgndg", "jtest_wet" : "ahreklajhrljkbstljknsb ljkstjkl stjkl hjklt " }, { "dsid" : 13, "name" : "debug", "description" : "Debug gsrhshysry", "wet" : "yeryersy ftudfl;hjkl;fdjkl;fgdkl;mfgydkl;mdyfjy", "jtest_wet" : "-uterjuytkkdytdykjt jdydyk t dkty" }, { "dsid" : 14, "name" : "mali_mrsid", "description" : "Mrjytdkydtkli", "wet" : " jtdfjfgyk dykl;kdy jkl;djry kl; djrykl;jdr djkl;kl;dy dj yrjdy 4", "jtest_wet" : " heht ehtetj je tjet j etj rye jry" } ]}';
jQuery.parseJSON2 = function(data) {
if (typeof data !== "string" || !data) {
return null;
}
// Make sure leading/trailing whitespace is removed (IE can't handle it)
data = jQuery.trim(data);
// Make sure the incoming data is actual JSON
// Logic borrowed from http://json.org/json2.js
// Try to use the native JSON parser first
if (window.JSON && window.JSON.parse) {
try {
return window.JSON.parse(data);
} catch (e) {
jQuery.error("Invalid JSON: " + data);
}
} else if (rvalidchars.test(data.replace(rvalidescape, "@").replace(rvalidtokens, "]").replace(rvalidbraces, ""))) {
return (new Function("return " + data))();
} else {
jQuery.error("Invalid JSON: " + data);
}
}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Current Version |
| ready |
New Version |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.