Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 


Quelle  ion2wasm.js   Sprache: JAVA

 
var ITERATIONS = 10;
var INNER_ITERATIONS = 100;

let instance = wasmEvalText(`(module
    (func (export "add") (param i32) (param i32) (result i32)
     local.get 0
     local.get 1
     i32.add
    )

    (func (export "no_arg") (result i32)
     i32.const 42
     i32.const 58
     i32.add
    )

    (global $g (mut i32) (i32.const 0))

    (func (export "set_global_one") (param i32)
     local.get 0
     global.set $g
    )

    (func (export "set_global_two") (param i32) (param i32)
     local.get 0
     local.get 1
     i32.add
     global.set $g
    )

    (func (export "glob") (result i32)
     global.get $g
    )
)`).exports;

function run(name, func) {
    for (let i = ITERATIONS; i --> 0;) {
        func();
    }
}

function testCallKnown() {
    for (let i = 0; i < INNER_ITERATIONS; i++) {
        assertEq(instance.add(i, i + 1), 2*i + 1);
    }
}

function testCallKnownRectifying() {
    for (let i = 0; i < INNER_ITERATIONS; i++) {
        assertEq(instance.add(i + 1), i+1);
    }
}

function jsAdd(x, y) {
    return (x|0) + (y|0) | 0;
}

function testCallGeneric() {
    var arr = [instance.add, jsAdd];
    for (let i = 0; i < INNER_ITERATIONS; i++) {
        assertEq(arr[i%2](i, i+1), 2*i + 1);
    }
}

function testCallGenericRectifying() {
    var arr = [instance.add, jsAdd];
    for (let i = 0; i < INNER_ITERATIONS; i++) {
        assertEq(arr[i%2](i+1), i + 1);
    }
}

function testCallScriptedGetter() {
    var obj = {};
    Object.defineProperty(obj, 'x', {
        get: instance.no_arg
    });
    for (let i = 0; i < INNER_ITERATIONS; i++) {
        assertEq(obj.x, 100);
    }
}

function testCallScriptedGetterRectifying() {
    var obj = {};
    Object.defineProperty(obj, 'x', {
        // Missing two arguments.
        get: instance.add
    });
    for (let i = 0; i < INNER_ITERATIONS; i++) {
        assertEq(obj.x, 0);
    }
}

function testCallScriptedSetter() {
    var obj = {};
    Object.defineProperty(obj, 'x', {
        set: instance.set_global_one
    });
    for (let i = 0; i < INNER_ITERATIONS; i++) {
        obj.x = i;
    }
    assertEq(instance.glob(), INNER_ITERATIONS-1);
}

function testCallScriptedSetterRectifying() {
    var obj = {};
    Object.defineProperty(obj, 'x', {
        set: instance.set_global_two
    });
    for (let i = 0; i < INNER_ITERATIONS; i++) {
        obj.x = i;
    }
    assertEq(instance.glob(), INNER_ITERATIONS-1);
}

function testFunctionApplyArray() {
    for (let i = 0; i < INNER_ITERATIONS; i++) {
        assertEq(instance.add.apply(null, [i, i + 1]), 2*i+1);
    }
}

function testFunctionApplyArrayRectifying() {
    for (let i = 0; i < INNER_ITERATIONS; i++) {
        assertEq(instance.add.apply(null, [i + 1]), i+1);
    }
}

function testFunctionApplyArgs() {
    function wrapper() {
        assertEq(instance.add.apply(null, arguments), 2*arguments[0]+1);
    }
    for (let i = 0; i < INNER_ITERATIONS; i++) {
        wrapper(i, i + 1);
    }
}

function testFunctionApplyArgsRectifying() {
    function wrapper() {
        assertEq(instance.add.apply(null, arguments), arguments[0]);
    }
    for (let i = 0; i < INNER_ITERATIONS; i++) {
        wrapper(i + 1);
    }
}

function testFunctionCall() {
    for (let i = 0; i < INNER_ITERATIONS; i++) {
        assertEq(instance.add.call(null, i, i + 1), 2*i+1);
    }
}

function testFunctionCallRectifying() {
    for (let i = 0; i < INNER_ITERATIONS; i++) {
        assertEq(instance.add.call(null, i + 1), i+1);
    }
}

run('call known', testCallKnown);
run('call known rectifying', testCallKnownRectifying);

run('call generic', testCallGeneric);
run('call generic rectifying', testCallGenericRectifying);

run('scripted getter', testCallScriptedGetter);
run('scripted getter rectifiying', testCallScriptedGetterRectifying);
run('scripted setter', testCallScriptedSetter);
run('scripted setter rectifiying', testCallScriptedSetterRectifying);

run('function.apply array', testFunctionApplyArray);
run('function.apply array rectifying', testFunctionApplyArrayRectifying);
run('function.apply args', testFunctionApplyArgs);
run('function.apply args rectifying', testFunctionApplyArgsRectifying);

run('function.call', testFunctionCall);
run('function.call rectifying', testFunctionCallRectifying);

Messung V0.5
C=97 H=96 G=96

¤ Dauer der Verarbeitung: 0.4 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Produkte
     Quellcodebibliothek

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Monitoring

Montastic status badge