Ferna::isString
JavaScript performance comparison
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.
| Test | Ops/sec | |
|---|---|---|
real string instanceof |
|
pending… |
real string prop |
|
pending… |
notreal string instanceof |
|
pending… |
notreal string prop |
|
pending… |
|
pending… | |
|
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:
- Revision 1: published by Mikhail Shestakov
- Revision 2: published
- Revision 3: published
- Revision 4: published by Mikhail Shestakov
0 comments