Grep vs Return

Benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Test runner

Ready to run.

Testing in
TestOps/sec
Grep
var imgNames = [3];
imgNames[0] = "";
imgNames[1] = "first";
imgNames[2] = "second";

$($.grep(imgNames, function(value, index) {
    return (index > 0);
})).each(function(i, val) {
});
ready
Return
var imgNames = [3];
imgNames[0] = "";
imgNames[1] = "first";
imgNames[2] = "second";

$(imgNames).each(function(i, val) {
    if (i == 0) {
        return;
    }
});
ready

Revisions

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