/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.commons.math.linear;

import java.util.Random;

import org.junit.Test;

/**
 * Tests multiplication speed of RealMatrixImpl using getEntry() vs native
 * arrays.
 * @version $Revision$ $Date$
 */
public class RealMatrixImplPerformanceTest {

    @Test
    public void testMultiplicationPerformance() throws Exception {
        int row1 = 3;
        int col1 = 2;
        int row2 = 2;
        int col2 = 4;
        Random r = new Random();
        for (int k = 0; k < 10; k++) {
            double[][] m1 = new double[row1][col1];
            for (int i = 0; i < row1; i++) {
                for (int j = 0; j < col1; j++) {
                    m1[i][j] = r.nextDouble() * 10;
                }
            }
            RealMatrix rm1 = new RealMatrixImpl(m1);
            double[][] m2 = new double[row2][col2];
            for (int i = 0; i < row2; i++) {
                for (int j = 0; j < col2; j++) {
                    m2[i][j] = r.nextDouble() * 10;
                }
            }
            RealMatrix rm2 = new RealMatrixImpl(m2);
            long start = System.currentTimeMillis();
            RealMatrix rm = rm1.multiply(rm2);
            long end = System.currentTimeMillis();
            System.out.println("time([" + row1 + "x" + col1 + "]*[" + row2 + "x" + col2 + "])=" + (end - start) + "ms");
            row1 *= 2;
            col1 *= 2;
            row2 *= 2;
            col2 *= 2;
        }
    }
}
