instanceof performance (v23)

Revision 23 of this benchmark created on


Setup

class Message {
    constructor($type) {
    }
}

class RenderResult1 extends Message{
    constructor() {
        super("RenderResult1");
    }
}

class RenderResult2 extends Message{
    constructor() {
        super("RenderResult2");
    }
}

class RenderResult3 extends Message{
    constructor() {
        super("RenderResult3");
    }
}

class RenderResult4 extends Message{
    constructor() {
        super("RenderResult4");
    }
}

class RenderResult5 extends Message{
    constructor() {
        super("RenderResult5");
    }
}

class RenderResult6 extends Message{
    constructor() {
        super("RenderResult6");
    }
}

class RenderResult7 extends Message{
    constructor() {
        super("RenderResult7");
    }
}

class RenderResult8 extends Message{
    constructor() {
        super("RenderResult8");
    }
}

class RenderResult9 extends Message{
    constructor() {
        super("RenderResult9");
    }
}

class RenderResult10 extends Message{
    constructor() {
        super("RenderResult10");
    }
}

function isMessage(message, protoType) {
    const name = protoType.constructor.name; 
    return name == message.$type;
}

Test runner

Ready to run.

Testing in
TestOps/sec
instanceof
const message = new RenderResult10();

switch (true) {
	case message instanceof RenderResult1:
		break;
	case message instanceof RenderResult2:
		break;
	case message instanceof RenderResult3:
		break;
	case message instanceof RenderResult4:
		break;
	case message instanceof RenderResult5:
		break;
	case message instanceof RenderResult6:
		break;
	case message instanceof RenderResult7:
		break;
	case message instanceof RenderResult8:
		break;
	case message instanceof RenderResult9:
		break;
	case message instanceof RenderResult10:
		break;
}
ready
property
const message = new RenderResult10();

switch (true) {
	case isMessage(message, RenderResult1.prototype):
		break;
	case isMessage(message, RenderResult2.prototype):
		break;
	case isMessage(message, RenderResult3.prototype):
		break;
	case isMessage(message, RenderResult4.prototype):
		break;
	case isMessage(message, RenderResult5.prototype):
		break;
	case isMessage(message, RenderResult6.prototype):
		break;
	case isMessage(message, RenderResult7.prototype):
		break;
	case isMessage(message, RenderResult8.prototype):
		break;
	case isMessage(message, RenderResult9.prototype):
		break;
	case isMessage(message, RenderResult10.prototype):
		break;
}
ready

Revisions

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