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
Test the performance of translating namespaced data attributes to camelcase. Figure out if returning a cached copy from the camelcase function is worth the overhead, versus just checking the cache before the camelcase call.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
var props = "prop prop-with-dashes long-prop-name-with-dashes".split(" "), propStr, i, v;
var p2CamelCaseDict = {};
var p2CamelCaseDict2 = {};
function propToNSCamelCase( prop )
{
return $.camelCase( "foo-" + prop );
}
function propToNSCamelCaseCache( prop )
{
return p2CamelCaseDict[ prop ] || ( p2CamelCaseDict[ prop ] = $.camelCase( "foo-" + prop ) );
}
function propToNSCamelCaseCache2( prop )
{
return ( p2CamelCaseDict2[ prop ] = $.camelCase( "foo-" + prop ) );
}
</script>
p2CamelCaseDict = {};
p2CamelCaseDict2 = {};
Ready to run.
Test | Ops/sec | |
---|---|---|
propToNSCamelCase( prop ) |
| ready |
propToNSCamelCaseCache(prop) |
| ready |
propToNSCamelCaseCache2(prop) |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.