benchmarks/sieve/src/test/java/org/apidesign/benchmark/sieve/n64/LongSieveTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 26 Jan 2016 05:54:37 +0100
changeset 1862 fa00fb053c72
parent 1860 benchmarks/sieve/src/test/java/org/apidesign/benchmark/sieve/SieveTest.java@4ce38f21f4cd
permissions -rw-r--r--
Extracting direct references to 64-bit operations
jaroslav@381
     1
/**
jaroslav@381
     2
 * Back 2 Browser Bytecode Translator
jaroslav@1787
     3
 * Copyright (C) 2012-2015 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@381
     4
 *
jaroslav@381
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@381
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@381
     7
 * the Free Software Foundation, version 2 of the License.
jaroslav@381
     8
 *
jaroslav@381
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@381
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@381
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@381
    12
 * GNU General Public License for more details.
jaroslav@381
    13
 *
jaroslav@381
    14
 * You should have received a copy of the GNU General Public License
jaroslav@381
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@381
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
jaroslav@381
    17
 */
jaroslav@1862
    18
package org.apidesign.benchmark.sieve.n64;
jaroslav@381
    19
jaroslav@381
    20
import java.io.IOException;
jaroslav@1854
    21
import net.java.html.js.JavaScriptBody;
jaroslav@381
    22
import org.apidesign.bck2brwsr.vmtest.Compare;
jaroslav@381
    23
import org.apidesign.bck2brwsr.vmtest.VMTest;
jaroslav@381
    24
import org.testng.annotations.Factory;
jaroslav@381
    25
jaroslav@381
    26
/**
jaroslav@381
    27
 *
jaroslav@381
    28
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@381
    29
 */
jaroslav@1862
    30
public class LongSieveTest extends Primes {
jaroslav@1862
    31
    public LongSieveTest() {
jaroslav@1854
    32
    }
jaroslav@1854
    33
jaroslav@1854
    34
    @JavaScriptBody(args = {  }, body = "return new Date().getTime();")
jaroslav@1854
    35
    protected int time() {
jaroslav@1854
    36
        return (int) System.currentTimeMillis();
jaroslav@381
    37
    }
jaroslav@381
    38
jaroslav@1860
    39
    @Compare
jaroslav@1862
    40
    public long oneThousand() throws IOException {
jaroslav@1862
    41
        LongSieveTest sieve = new LongSieveTest();
jaroslav@1854
    42
        int now = time();
jaroslav@1862
    43
        long res = sieve.compute(1000);
jaroslav@1854
    44
        int took = time() - now;
jaroslav@1854
    45
        log("oneThousand in " + took + " ms");
jaroslav@1854
    46
        return res;
jaroslav@836
    47
    }
jaroslav@1857
    48
jaroslav@1862
    49
/*
jaroslav@1860
    50
    @Compare(slowdown = 3.0)
jaroslav@1862
    51
    public long fiveThousand() throws IOException {
jaroslav@1862
    52
        LongSieveTest sieve = new LongSieveTest();
jaroslav@1857
    53
        int now = time();
jaroslav@1862
    54
        long res = sieve.compute(5000);
jaroslav@1857
    55
        int took = time() - now;
jaroslav@1857
    56
        log("oneThousand in " + took + " ms");
jaroslav@1857
    57
        return res;
jaroslav@1857
    58
    }
jaroslav@1860
    59
    @Compare(slowdown = 3.0)
jaroslav@1862
    60
    public long tenThousand() throws IOException {
jaroslav@1862
    61
        LongSieveTest sieve = new LongSieveTest();
jaroslav@1860
    62
        int now = time();
jaroslav@1862
    63
        long res = sieve.compute(10000);
jaroslav@1860
    64
        int took = time() - now;
jaroslav@1860
    65
        log("oneThousand in " + took + " ms");
jaroslav@1860
    66
        return res;
jaroslav@1860
    67
    }
jaroslav@1862
    68
*/
jaroslav@381
    69
    @Factory
jaroslav@381
    70
    public static Object[] create() {
jaroslav@1862
    71
        return VMTest.create(LongSieveTest.class);
jaroslav@1854
    72
    }
jaroslav@1854
    73
jaroslav@1854
    74
    @JavaScriptBody(args = { "msg" }, body = "if (typeof console !== 'undefined') console.log(msg);")
jaroslav@1854
    75
    @Override
jaroslav@1854
    76
    protected void log(String msg) {
jaroslav@1857
    77
        System.err.println(msg);
jaroslav@381
    78
    }
jaroslav@381
    79
}