import { Type as NType } from "../src/type_utils.ts";

const sTypes = ["int", "string", "bool"];

let i = 0;

setInterval(() => {
    const r1 = Math.floor(Math.random() * 10 / 3);
    const r2 = Math.floor(Math.random() * 10 / 3);

    console.log(`run ${i} comparing ${sTypes[r1]} and ${sTypes[r2]}`);

    const _a: NType = r1;
    const _b: NType = r2

    Deno.bench("NType (boolop)", () => {
        _a === _b || _a + _b !== 8;
    });

    Deno.bench("NType (switch)", () => {
        let c: boolean;

        if (_a === _b) {
            c = true;
        } else {
            switch (_a + _b) {
                case 4:
                case 10: c = true; break
                case 8: c = false;
            }
        }
    });

    const a = sTypes[r1];
    const b = sTypes[r2];

    Deno.bench("SType (if)", () => {
        let c: boolean;

        if (a === b) {
            c = true;
        } else {
            if ((a === "int" && b === "string") || (a === "string" && b === "int")) {
                c = true;
            } else if ((a === "int" && b === "boolean") || (a === "boolean" && b === "int")) {
                c = false;
            } else if ((a === "boolean" && b === "string") || (a === "string" && b === "boolean")) {
                c = true;
            }
        }
    });

    Deno.bench("SType (boolop)", () => {
        let c: boolean;

        if (a === b) {
            c = true;
        } else {
            c = (
                ((a === "int" && b === "string") || (a === "string" && b === "int"))
                || ((a === "boolean" && b === "string") || (a === "string" && b === "boolean"))
                || !((a === "int" && b === "boolean") || (a === "boolean" || b === "int"))
            );
        }
    });

    Deno.bench("SType (if+includes)", () => {
        let c: boolean;

        if (a === b) {
            c = true;
        } else {
            c = (
                ([a, b].includes("int") && [a, b].includes("string"))
                || ([a, b].includes("boolean") && [a, b].includes("string"))
                || !([a, b].includes("int") && [a, b].includes("boolean"))
            );
        }
    });

    i++;
}, 5000);