author | Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
Sun, 22 Jun 2014 17:19:16 +0200 | |
branch | defprop |
changeset 1633 | a34e2191b6be |
parent 537 | 7dbd0a097e44 |
child 1787 | ea12a3bb4b33 |
permissions | -rw-r--r-- |
jaroslav@381 | 1 |
/** |
jaroslav@381 | 2 |
* Back 2 Browser Bytecode Translator |
jaroslav@381 | 3 |
* Copyright (C) 2012 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@381 | 18 |
package org.apidesign.benchmark.matrixmul; |
jaroslav@381 | 19 |
|
jaroslav@381 | 20 |
import java.io.IOException; |
jaroslav@381 | 21 |
import org.apidesign.bck2brwsr.vmtest.Compare; |
jaroslav@381 | 22 |
import org.apidesign.bck2brwsr.vmtest.VMTest; |
jaroslav@381 | 23 |
import org.testng.annotations.Factory; |
jaroslav@381 | 24 |
|
jaroslav@381 | 25 |
/** |
jaroslav@381 | 26 |
* |
jaroslav@381 | 27 |
* @author Jaroslav Tulach <jtulach@netbeans.org> |
jaroslav@381 | 28 |
*/ |
jaroslav@381 | 29 |
public class MatrixTest { |
jaroslav@381 | 30 |
public MatrixTest() { |
jaroslav@381 | 31 |
} |
jaroslav@381 | 32 |
|
jaroslav@537 | 33 |
@Compare(scripting = false) |
jaroslav@836 | 34 |
public String oneIteration() throws IOException { |
jaroslav@836 | 35 |
|
jaroslav@836 | 36 |
Matrix m1 = new Matrix(5); |
jaroslav@836 | 37 |
Matrix m2 = new Matrix(5); |
jaroslav@836 | 38 |
|
jaroslav@836 | 39 |
m1.generateData(); |
jaroslav@836 | 40 |
m2.generateData(); |
jaroslav@836 | 41 |
|
jaroslav@836 | 42 |
Matrix res = m1.multiply(m2); |
jaroslav@836 | 43 |
|
jaroslav@836 | 44 |
StringBuilder sb = new StringBuilder(); |
jaroslav@836 | 45 |
res.printOn(sb); |
jaroslav@836 | 46 |
return sb.toString(); |
jaroslav@836 | 47 |
} |
jaroslav@836 | 48 |
|
jaroslav@836 | 49 |
@Compare(scripting = false) |
jaroslav@537 | 50 |
public String tenThousandIterations() throws IOException { |
jaroslav@381 | 51 |
|
jaroslav@381 | 52 |
Matrix m1 = new Matrix(5); |
jaroslav@381 | 53 |
Matrix m2 = new Matrix(5); |
jaroslav@381 | 54 |
|
jaroslav@381 | 55 |
m1.generateData(); |
jaroslav@381 | 56 |
m2.generateData(); |
jaroslav@381 | 57 |
|
jaroslav@381 | 58 |
Matrix res = null; |
jaroslav@520 | 59 |
for (int i = 0; i < 10000; i++) { |
jaroslav@520 | 60 |
res = m1.multiply(m2); |
jaroslav@520 | 61 |
m1 = res; |
jaroslav@381 | 62 |
} |
jaroslav@381 | 63 |
|
jaroslav@381 | 64 |
StringBuilder sb = new StringBuilder(); |
jaroslav@381 | 65 |
res.printOn(sb); |
jaroslav@381 | 66 |
return sb.toString(); |
jaroslav@381 | 67 |
} |
jaroslav@381 | 68 |
|
jaroslav@836 | 69 |
@Compare(scripting = false) |
jaroslav@836 | 70 |
public String tenUselessIterations() throws IOException { |
jaroslav@836 | 71 |
|
jaroslav@836 | 72 |
Matrix m1 = new Matrix(5); |
jaroslav@836 | 73 |
Matrix m2 = new Matrix(5); |
jaroslav@836 | 74 |
|
jaroslav@836 | 75 |
m1.generateData(); |
jaroslav@836 | 76 |
m2.generateData(); |
jaroslav@836 | 77 |
|
jaroslav@836 | 78 |
Matrix res = null; |
jaroslav@836 | 79 |
for (int i = 0; i < 10; i++) { |
jaroslav@836 | 80 |
res = m1.multiply(m2); |
jaroslav@836 | 81 |
m1 = res; |
jaroslav@836 | 82 |
} |
jaroslav@836 | 83 |
|
jaroslav@836 | 84 |
StringBuilder sb = new StringBuilder(); |
jaroslav@836 | 85 |
res.printOn(sb); |
jaroslav@836 | 86 |
return sb.toString(); |
jaroslav@836 | 87 |
} |
jaroslav@836 | 88 |
|
jaroslav@836 | 89 |
|
jaroslav@381 | 90 |
@Factory |
jaroslav@381 | 91 |
public static Object[] create() { |
jaroslav@381 | 92 |
return VMTest.create(MatrixTest.class); |
jaroslav@381 | 93 |
} |
jaroslav@381 | 94 |
} |