Skip to content

Commit

Permalink
Merge pull request JuliaLang#8813 from pabloferz/pf/perf
Browse files Browse the repository at this point in the history
Java microbenchmark fix
  • Loading branch information
StefanKarpinski committed Oct 25, 2014
2 parents 89befaf + a6e8946 commit e362fab
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
21 changes: 21 additions & 0 deletions test/perf/micro/java/src/main/java/Complex.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
public class Complex {
private final double re;
private final double im;

public Complex(double real, double imag) {
re = real;
im = imag;
}

public static double abs(Complex z) {
return Math.sqrt(z.re*z.re + z.im*z.im);
}

public static Complex add(Complex a, Complex b) {
return new Complex(a.re + b.re, a.im + b.im);
}

public static Complex mul(Complex a, Complex b) {
return new Complex(a.re*b.re - a.im*b.im, a.re*b.im + a.im*b.re);
}
}
22 changes: 6 additions & 16 deletions test/perf/micro/java/src/main/java/PerfBLAS.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,32 +245,22 @@ private static double pisum() {
return sum;
}

private static int mandel(double zReal, double zImag) {
private static int mandel(double re, double im) {
int n = 0;
double cReal = zReal;
double cImag = zImag;
Complex z = new Complex(re, im);
Complex c = new Complex(re, im);
for (n=0; n<=79; ++n) {
if (complexAbs(zReal,zImag) > 2.0) {
if (Complex.abs(z) > 2.0) {
n -= 1;
break;
}

// z^2
double zSquaredReal = zReal*zReal-zImag*zImag;
double zSquaredImag = zReal*zImag+zImag*zReal;

// +c
zReal = zSquaredReal+cReal;
zImag = zSquaredImag+cImag;

// z = z*z + c
z = Complex.add(Complex.mul(z, z), c)
}
return n+1;
}

private static double complexAbs(double zReal, double zImag) {
return Math.sqrt(zReal*zReal + zImag*zImag);
}

private static int mandelperf() {
int mandel_sum = 0;
for (double re=-2.0; re<=0.5; re+=0.1) {
Expand Down

0 comments on commit e362fab

Please sign in to comment.