parseInt vs. replace(/px/,'') (v4)

Revision 4 of this benchmark created on


Description

Check when elmWidth = 'XXX.XXXpx' and elmWidth = 'XXXpx'

Setup

var elmWidth = '345px';

Test runner

Ready to run.

Testing in
TestOps/sec
parseInt()
parseInt(elmWidth);
ready
replace(/px/,'')
elmWidth.replace(/px/,'');
ready
slice
+elmWidth.slice(0, -2)
ready
parseInt() w/ radix
parseInt(elmWidth, 10);
ready
+substring
+elmWidth.substring(0, elmWidth.length - 2)
ready
~~substring
~~elmWidth.substring(0, elmWidth.length - 2);
ready
>>> substring
elmWidth.substring(0, elmWidth.length - 2)>>>0;
ready
~~parseInt() w/ radix
~~parseInt(elmWidth, 10);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.