Slice vs Substr vs Substring vs [ ] Methods (v36)

Revision 36 of this benchmark created by David Martinez on


Description

This is comparing the runtimes of substr, substring, and slice in a string for large (10000 character) string size.

Setup

var str = "LOri18BDzK2lb/zPVrydHAhmZvCPnUwK9CeA2Js+Dni9iv8KwfuryHi+Cm21zx1zsh6cl7bpWuyiL3PaTKru8MMmKjXP0oBzKBjzxx8PuKFuHZM9m9L2bujluu5PqBdzKZWYcS3Gs9F8uxmTxZawpmL//zBGXXN6Zb7KvNPY33tlzlF3lsdBxA/doRmZnJ0ul+NT7mgCaKJBksV/WaIPf1u76FX0pcBi3EEXJiJXB0c56ZhhJzZ0ovYvYzWFlwy1YdzICnl+pYSQ/kdClRuhRtdrYEGYmNznPSo6VlC8GN0Z9SIYmOUAnNaYDBeG/lgqv4keSpGVc3dKggk6QGRoDM+3wyX+AzL5nUUS7Z3V6ZkAblC+lNErQb/xTtzeH2NSuIHGC3YqODCwG8ay/dMg8JlKnhTYqQz3eU05RQOw813tGWgqgGgrAo98L2dcHIUqYilQfnBVa/QPXWDzHGryuKL3k+1qyRaMUaNW6OdGMotiMCOxTvMbScKYmQ5Qj2c8n+kGGD5my22DanapePrU2myW9QapFP/ZdHlw3oI7cU9XKwIDg8RAjmGsMGdyxbjajz3Tol+OpAufC8GxAxIZ/qzWFV3Y87nhN483jwLMpmt9loXnvnXHe25ucR2mBXpu//wQA4i1cN7SyGRJP2+UiOOiphlx/V5mr6hy852eW/GqhP3uW6ngA4TvayejVchS0Bg5VATIC+kr0Z1yOvLk8TV1wgcp0XUQ1q2XTpMvVPfHFHD7vDRA17PA17p9AOGRXH9RB5v41Oh1CM2HgALI72U/YfzCWkKZhw3RkxhBeyJnUchu0T/Q7ytLyVYYgXS+9FXj2t07iInnhWGAZxwxDSr6yFUpO1fYtiEbioXF+QXw0U2CtYA0FJWQZLqXeVtIQiR/PCYDdtNwTQRkFh4PQOgG0KcFMedOhZc8F6CS+N01O4XqteIgqVew/3/SRpy2Q47e9xlrc14wvApXacSmX3EyG0XfMFEsmXwMwNn3GB+yUQOf7WsuPvXQ8UwiNR1tSTBvCkJneufYLx249W7wqZoVLwoszOKWA/0qfHkwwGVaOzBom5ngKld5xGmOrdFiJFvlcShEYn8SKZbLUyqXMbIp/0xH6q+jC8ivzYIoyMNLW1eojYwRetVkgIs5JvTNUI2woVnWfd9bo5mbnwEyUZlR+xEagq/hODO1WW9AVa51LLarTQHJ6nwqg/e8eJ10whIJdOoBmND87W7CUS95jkdaosbfelHWuj3h/eEJRdbM1hXcF+WVF1B8xKA8utfhPCFZ5sgpT+SM0HzrM2KvoB9SnL11t2jJw6dt7bQ+w+qXhZq7cH3+Q6MX2FD2o8FHg0uTm3mmvhVhp/KSORh/wafEtozaYEjYFgo8nu";
    var n = 0;
    var len1 = 256;

Teardown


    n = (n + 1) % 256;
  

Test runner

Ready to run.

Testing in
TestOps/sec
Substring
str.substring(n, n + len1);
ready
substr
str.substr(n, n + len1);
ready
slice
str.slice(n, len1);
ready

Revisions

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