jaroslav@381: /** jaroslav@381: * Back 2 Browser Bytecode Translator jaroslav@1787: * Copyright (C) 2012-2015 Jaroslav Tulach jaroslav@381: * jaroslav@381: * This program is free software: you can redistribute it and/or modify jaroslav@381: * it under the terms of the GNU General Public License as published by jaroslav@381: * the Free Software Foundation, version 2 of the License. jaroslav@381: * jaroslav@381: * This program is distributed in the hope that it will be useful, jaroslav@381: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@381: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@381: * GNU General Public License for more details. jaroslav@381: * jaroslav@381: * You should have received a copy of the GNU General Public License jaroslav@381: * along with this program. Look for COPYING file in the top folder. jaroslav@381: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@381: */ jaroslav@1854: package org.apidesign.benchmark.sieve; jaroslav@381: jaroslav@381: import java.io.IOException; jaroslav@1854: import net.java.html.js.JavaScriptBody; jaroslav@381: import org.apidesign.bck2brwsr.vmtest.Compare; jaroslav@381: import org.apidesign.bck2brwsr.vmtest.VMTest; jaroslav@381: import org.testng.annotations.Factory; jaroslav@381: jaroslav@381: /** jaroslav@381: * jaroslav@381: * @author Jaroslav Tulach jaroslav@381: */ jaroslav@1854: public class SieveTest extends Primes { jaroslav@1854: public SieveTest() { jaroslav@1854: } jaroslav@1854: jaroslav@1854: @JavaScriptBody(args = { }, body = "return new Date().getTime();") jaroslav@1854: protected int time() { jaroslav@1854: return (int) System.currentTimeMillis(); jaroslav@381: } jaroslav@381: jaroslav@537: @Compare(scripting = false) jaroslav@1854: public int oneThousand() throws IOException { jaroslav@1854: SieveTest sieve = new SieveTest(); jaroslav@1854: int now = time(); jaroslav@1854: int res = sieve.compute(1000); jaroslav@1854: int took = time() - now; jaroslav@1854: log("oneThousand in " + took + " ms"); jaroslav@1854: return res; jaroslav@836: } jaroslav@1857: jaroslav@1857: @Compare(scripting = false) jaroslav@1857: public int fiveThousand() throws IOException { jaroslav@1857: SieveTest sieve = new SieveTest(); jaroslav@1857: int now = time(); jaroslav@1857: int res = sieve.compute(5000); jaroslav@1857: int took = time() - now; jaroslav@1857: log("oneThousand in " + took + " ms"); jaroslav@1857: return res; jaroslav@1857: } jaroslav@836: jaroslav@381: @Factory jaroslav@381: public static Object[] create() { jaroslav@1854: return VMTest.create(SieveTest.class); jaroslav@1854: } jaroslav@1854: jaroslav@1854: @JavaScriptBody(args = { "msg" }, body = "if (typeof console !== 'undefined') console.log(msg);") jaroslav@1854: @Override jaroslav@1854: protected void log(String msg) { jaroslav@1857: System.err.println(msg); jaroslav@381: } jaroslav@381: }