use of maspack.util.FunctionTimer in project artisynth_core by artisynth.
the class Matrix3dTest method timing.
public void timing() {
int nsamps = 100000;
RandomGenerator.setSeed(0x1234);
FunctionTimer timer = new FunctionTimer();
Matrix3d[] MR = new Matrix3d[nsamps];
Matrix3d[] M1 = new Matrix3d[nsamps];
Matrix3d[] M2 = new Matrix3d[nsamps];
Vector3d[] vr = new Vector3d[nsamps];
Vector3d[] v1 = new Vector3d[nsamps];
for (int i = 0; i < nsamps; i++) {
MR[i] = new Matrix3d();
M1[i] = new Matrix3d();
M1[i].setRandom();
M2[i] = new Matrix3d();
M2[i].setRandom();
vr[i] = new Vector3d();
v1[i] = new Vector3d();
v1[i].setRandom();
}
int cnt = 1000;
for (int k = 0; k < cnt; k++) {
for (int i = 0; i < nsamps; i++) {
MR[i].mul(M1[i], M2[i]);
MR[i].mul(vr[i], v1[i]);
MR[i].solve(vr[i], v1[i]);
MR[i].mulInverse(vr[i], v1[i]);
}
}
timer.start();
for (int k = 0; k < cnt; k++) {
for (int i = 0; i < nsamps; i++) {
MR[i].mul(M1[i], M2[i]);
}
}
timer.stop();
System.out.println("matrix mul: " + timer.result(cnt * nsamps));
timer.start();
for (int k = 0; k < cnt; k++) {
for (int i = 0; i < nsamps; i++) {
MR[i].mul(vr[i], v1[i]);
}
}
timer.stop();
System.out.println("vector mul: " + timer.result(cnt * nsamps));
timer.start();
for (int k = 0; k < cnt; k++) {
for (int i = 0; i < nsamps; i++) {
MR[i].solve(vr[i], v1[i]);
}
}
timer.stop();
System.out.println("vector solve: " + timer.result(cnt * nsamps));
timer.start();
for (int k = 0; k < cnt; k++) {
for (int i = 0; i < nsamps; i++) {
MR[i].mulInverse(vr[i], v1[i]);
}
}
timer.stop();
System.out.println("vector mulInverse: " + timer.result(cnt * nsamps));
}
use of maspack.util.FunctionTimer in project artisynth_core by artisynth.
the class QRDecompositionTest method timingTests.
private void timingTests() {
int baseTimingCnt = 100000;
int numTrials = 10;
int[] matsizes = new int[] { 4, 8, 16, 32, 4, 8, 16, 32, 64 };
NumberFormat ifmt = new NumberFormat("%3d");
NumberFormat ffmt = new NumberFormat("%7.2f");
System.out.println("matsize time");
for (int k = 0; k < matsizes.length; k++) {
int n = matsizes[k];
int timingCnt = baseTimingCnt / (n * n);
MatrixNd M = new MatrixNd(n, n);
QRDecomposition qr = new QRDecomposition();
FunctionTimer timer = new FunctionTimer();
double qrdTime = 0;
for (int cnt = 0; cnt < numTrials; cnt++) {
M.setRandom();
timer.start();
for (int i = 0; i < timingCnt; i++) {
qr.factor(M);
}
timer.stop();
qrdTime += timer.getTimeUsec() / timingCnt;
}
qrdTime /= numTrials;
System.out.println(" " + ifmt.format(n) + " " + ffmt.format(qrdTime));
}
}
use of maspack.util.FunctionTimer in project artisynth_core by artisynth.
the class SVDecomposition3dTest method checkTiming.
public void checkTiming(int nrand) {
Matrix3d M1 = new Matrix3d();
M1.setRandom();
Matrix3d U = new Matrix3d();
Matrix3d V = new Matrix3d();
Vector3d s = new Vector3d();
SVDecomposition3d svd = new SVDecomposition3d();
int cnt = 20000;
FunctionTimer timer = new FunctionTimer();
for (int k = 0; k < nrand; k++) {
M1.setRandom();
timer.restart();
for (int i = 0; i < cnt; i++) {
svd.factor(M1);
}
timer.stop();
}
System.out.println(timer.result(cnt * nrand));
}
use of maspack.util.FunctionTimer in project artisynth_core by artisynth.
the class Vector3d method main.
public static void main(String[] args) {
FunctionTimer timer = new FunctionTimer();
Vector3d v1 = new Vector3d();
Vector3d v2 = new Vector3d();
Vector3d vr = new Vector3d();
v1.setRandom();
v2.setRandom();
int cnt = 10000000;
for (int i = 0; i < cnt; i++) {
vr.sub(v1, v2);
vr.add(v1, v2);
v1.dot(v2);
}
timer.start();
for (int i = 0; i < cnt; i++) {
vr.sub(v1, v2);
}
timer.stop();
System.out.println("Vector3d.sub: " + timer.result(cnt));
timer.start();
for (int i = 0; i < cnt; i++) {
vr.add(v1, v2);
}
timer.stop();
System.out.println("Vector3d.add: " + timer.result(cnt));
timer.start();
for (int i = 0; i < cnt; i++) {
v1.dot(v2);
}
timer.stop();
System.out.println("Vector3d.dot: " + timer.result(cnt));
timer.start();
for (int i = 0; i < cnt; i++) {
vr.scale(1 / .33, v1);
}
timer.stop();
System.out.println("Vector3d.scale: " + timer.result(cnt));
// timer.start();
// for (int i = 0; i < cnt; i++) {
// vr.divide (.33, v1);
// }
// timer.stop();
// System.out.println ("Vector3d.divide: " + timer.result (cnt));
}
use of maspack.util.FunctionTimer in project artisynth_core by artisynth.
the class SparseTiming method main.
public static void main(String[] args) {
int loopCnt;
FunctionTimer timer = new FunctionTimer();
for (int size = 50; size <= 200; size += 50) {
System.out.println("size: " + size);
MatrixNd MR = new MatrixNd(size, size);
MatrixNd M1 = new MatrixNd(size, size);
MatrixNd M2 = new MatrixNd(size, size);
VectorNd v1 = new VectorNd(size);
VectorNd vr = new VectorNd(size);
SparseMatrixNd SR = new SparseMatrixNd(size, size);
SparseMatrixNd S1 = new SparseMatrixNd(size, size);
SparseMatrixNd S2 = new SparseMatrixNd(size, size);
loopCnt = 10;
S1.setRandom();
S2.setRandom();
M1.set(S1);
M2.set(S2);
v1.setRandom();
timer.start();
for (int i = 0; i < loopCnt; i++) {
MR.mul(M1, M2);
}
timer.stop();
System.out.println("dense matrix multiply: " + timer.result(loopCnt));
timer.start();
for (int i = 0; i < loopCnt; i++) {
SR.mul(S1, S2);
}
timer.stop();
System.out.println("sparse matrix multiply: " + timer.result(loopCnt));
loopCnt *= size;
timer.start();
for (int i = 0; i < loopCnt; i++) {
vr.mul(MR, v1);
}
timer.stop();
System.out.println("dense vector multiply: " + timer.result(loopCnt));
timer.start();
for (int i = 0; i < loopCnt; i++) {
vr.mul(SR, v1);
}
timer.stop();
System.out.println("sparse vector multiply: " + timer.result(loopCnt));
if (!MR.epsilonEquals(SR, 1e-9)) {
System.out.println("results not equal");
}
}
}
Aggregations