benchmarks/matrix-multiplication/src/test/java/org/apidesign/benchmark/matrixmul/MatrixTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 25 Dec 2012 14:07:02 +0100
changeset 381 70d15cf323ba
child 520 b03a2d2b1fdc
permissions -rw-r--r--
Can execute the matrix multiplication test using VMTest
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 static final int ITERATION_COUNT = 10;
jaroslav@381
    31
    
jaroslav@381
    32
    public MatrixTest() {
jaroslav@381
    33
    }
jaroslav@381
    34
jaroslav@381
    35
    @Compare public String tenThousandIterations() throws IOException {
jaroslav@381
    36
    
jaroslav@381
    37
        Matrix m1 = new Matrix(5);
jaroslav@381
    38
        Matrix m2 = new Matrix(5);
jaroslav@381
    39
        
jaroslav@381
    40
        m1.generateData();
jaroslav@381
    41
        m2.generateData();
jaroslav@381
    42
        
jaroslav@381
    43
        Matrix res = null;
jaroslav@381
    44
        for (int i = 0; i < ITERATION_COUNT; i++) {
jaroslav@381
    45
            Matrix m = m1.multiply(m2);
jaroslav@381
    46
            if (res != null && !res.equals(m)) {
jaroslav@381
    47
                return "different";
jaroslav@381
    48
            }
jaroslav@381
    49
            res = m;
jaroslav@381
    50
        }
jaroslav@381
    51
        
jaroslav@381
    52
        StringBuilder sb = new StringBuilder();
jaroslav@381
    53
        res.printOn(sb);
jaroslav@381
    54
        return sb.toString();
jaroslav@381
    55
    }
jaroslav@381
    56
    
jaroslav@381
    57
    @Factory
jaroslav@381
    58
    public static Object[] create() {
jaroslav@381
    59
        return VMTest.create(MatrixTest.class);
jaroslav@381
    60
    }
jaroslav@381
    61
}