Ferna::isString

JavaScript performance comparison

Revision 4 of this test case created by Mikhail Shestakov

Info

Fastest way to check if variable is siring

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    if (!"dsfsad".isString) {
        String.prototype.isString = true;
   
        $ = {};
   
        $.defineMethod = function(obj, method, fn) {
                Object.defineProperty(obj, method, {
                        value: fn,
                        enumerable: false
                });
        };
   
        $.defineMethod(window, 'isString', function (value){
                return typeof value == 'string' || value instanceof String;
        });
   
        $.defineMethod(window, 'isString2', function (value){
                return value.isString? true: false;
        });
   
    window.isString3 = function(value){return typeof value == 'string' || value instanceof String;}
    }
   
    var a = "DFADSF";
    var b = {c:10};
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
real string instanceof
isString(a);

 
pending…
real string prop
isString2(a);
pending…
notreal string instanceof
isString(b);
pending…
notreal string prop
isString2(b);
pending…
isString3(a);
pending…
isString3(b);
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment