benchmarks/matrix-multiplication/src/test/java/org/apidesign/benchmark/matrixmul/MatrixTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Wed, 23 Jan 2013 08:42:00 +0100
branchmodel
changeset 537 7dbd0a097e44
parent 520 b03a2d2b1fdc
child 836 eefe5c8438d4
permissions -rw-r--r--
Don't run the Matrix multiplication test in Rhino - it is too slow
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@537
    34
    public String tenThousandIterations() throws IOException {
jaroslav@381
    35
    
jaroslav@381
    36
        Matrix m1 = new Matrix(5);
jaroslav@381
    37
        Matrix m2 = new Matrix(5);
jaroslav@381
    38
        
jaroslav@381
    39
        m1.generateData();
jaroslav@381
    40
        m2.generateData();
jaroslav@381
    41
        
jaroslav@381
    42
        Matrix res = null;
jaroslav@520
    43
        for (int i = 0; i < 10000; i++) {
jaroslav@520
    44
            res = m1.multiply(m2);
jaroslav@520
    45
            m1 = res;
jaroslav@381
    46
        }
jaroslav@381
    47
        
jaroslav@381
    48
        StringBuilder sb = new StringBuilder();
jaroslav@381
    49
        res.printOn(sb);
jaroslav@381
    50
        return sb.toString();
jaroslav@381
    51
    }
jaroslav@381
    52
    
jaroslav@381
    53
    @Factory
jaroslav@381
    54
    public static Object[] create() {
jaroslav@381
    55
        return VMTest.create(MatrixTest.class);
jaroslav@381
    56
    }
jaroslav@381
    57
}