Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 99338 invoked from network); 27 Jan 2011 00:31:49 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 27 Jan 2011 00:31:49 -0000 Received: (qmail 70186 invoked by uid 500); 27 Jan 2011 00:31:49 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 70059 invoked by uid 500); 27 Jan 2011 00:31:48 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 70052 invoked by uid 99); 27 Jan 2011 00:31:48 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 27 Jan 2011 00:31:48 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 27 Jan 2011 00:31:47 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id CB4882388A68; Thu, 27 Jan 2011 00:31:26 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1063931 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/FastMathTestPerformance.java Date: Thu, 27 Jan 2011 00:31:26 -0000 To: commits@commons.apache.org From: erans@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110127003126.CB4882388A68@eris.apache.org> Author: erans Date: Thu Jan 27 00:31:26 2011 New Revision: 1063931 URL: http://svn.apache.org/viewvc?rev=1063931&view=rev Log: Added functions. Replaced hard-coded numbers by a named constant. Changed display format for ratios. Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/FastMathTestPerformance.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/FastMathTestPerformance.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/FastMathTestPerformance.java?rev=1063931&r1=1063930&r2=1063931&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/FastMathTestPerformance.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/FastMathTestPerformance.java Thu Jan 27 00:31:26 2011 @@ -30,11 +30,12 @@ import org.junit.Test; */ public class FastMathTestPerformance { private static final int RUNS = Integer.parseInt(System.getProperty("testRuns","10000000")); + private static final double F1 = 1d / RUNS; // Header format private static final String FMT_HDR = "%-5s %13s %13s %13s Runs=%d Java %s (%s) %s (%s)"; // Detail format - private static final String FMT_DTL = "%-5s %6d %6.2f %6d %6.2f %6d %6.2f"; + private static final String FMT_DTL = "%-5s %6d %6.1f %6d %6.4f %6d %6.4f"; @BeforeClass public static void header() { @@ -56,6 +57,7 @@ public class FastMathTestPerformance { mathTime / RUNS, (double) mathTime / unitTime )); } + @Test public void testLog() { double x = 0; @@ -80,23 +82,69 @@ public class FastMathTestPerformance { } @Test + public void testLog10() { + double x = 0; + long time = System.nanoTime(); + for (int i = 0; i < RUNS; i++) + x += StrictMath.log10(Math.PI + i/* 1.0 + i/1e9 */); + long strictMath = System.nanoTime() - time; + + x = 0; + time = System.nanoTime(); + for (int i = 0; i < RUNS; i++) + x += FastMath.log10(Math.PI + i/* 1.0 + i/1e9 */); + long fastTime = System.nanoTime() - time; + + x = 0; + time = System.nanoTime(); + for (int i = 0; i < RUNS; i++) + x += Math.log10(Math.PI + i/* 1.0 + i/1e9 */); + long mathTime = System.nanoTime() - time; + + report("log10",strictMath,fastTime,mathTime); + } + + @Test + public void testLog1p() { + double x = 0; + long time = System.nanoTime(); + for (int i = 0; i < RUNS; i++) + x += StrictMath.log1p(Math.PI + i/* 1.0 + i/1e9 */); + long strictMath = System.nanoTime() - time; + + x = 0; + time = System.nanoTime(); + for (int i = 0; i < RUNS; i++) + x += FastMath.log1p(Math.PI + i/* 1.0 + i/1e9 */); + long fastTime = System.nanoTime() - time; + + x = 0; + time = System.nanoTime(); + for (int i = 0; i < RUNS; i++) + x += Math.log1p(Math.PI + i/* 1.0 + i/1e9 */); + long mathTime = System.nanoTime() - time; + + report("log1p",strictMath,fastTime,mathTime); + } + + @Test public void testPow() { double x = 0; long time = System.nanoTime(); for (int i = 0; i < RUNS; i++) - x += StrictMath.pow(Math.PI + i / 1e6, i / 1e6); + x += StrictMath.pow(Math.PI + i * F1, i * F1); long strictTime = System.nanoTime() - time; x = 0; time = System.nanoTime(); for (int i = 0; i < RUNS; i++) - x += FastMath.pow(Math.PI + i / 1e6, i / 1e6); + x += FastMath.pow(Math.PI + i * F1, i * F1); long fastTime = System.nanoTime() - time; x = 0; time = System.nanoTime(); for (int i = 0; i < RUNS; i++) - x += Math.pow(Math.PI + i / 1e6, i / 1e6); + x += Math.pow(Math.PI + i * F1, i * F1); long mathTime = System.nanoTime() - time; report("pow",strictTime,fastTime,mathTime); } @@ -106,19 +154,19 @@ public class FastMathTestPerformance { double x = 0; long time = System.nanoTime(); for (int i = 0; i < RUNS; i++) - x += StrictMath.exp(i / 1000000.0); + x += StrictMath.exp(i * F1); long strictTime = System.nanoTime() - time; x = 0; time = System.nanoTime(); for (int i = 0; i < RUNS; i++) - x += FastMath.exp(i / 1000000.0); + x += FastMath.exp(i * F1); long fastTime = System.nanoTime() - time; x = 0; time = System.nanoTime(); for (int i = 0; i < RUNS; i++) - x += Math.exp(i / 1000000.0); + x += Math.exp(i * F1); long mathTime = System.nanoTime() - time; report("exp",strictTime,fastTime,mathTime); @@ -129,19 +177,19 @@ public class FastMathTestPerformance { double x = 0; long time = System.nanoTime(); for (int i = 0; i < RUNS; i++) - x += StrictMath.sin(i / 1000000.0); + x += StrictMath.sin(i * F1); long strictTime = System.nanoTime() - time; x = 0; time = System.nanoTime(); for (int i = 0; i < RUNS; i++) - x += FastMath.sin(i / 1000000.0); + x += FastMath.sin(i * F1); long fastTime = System.nanoTime() - time; x = 0; time = System.nanoTime(); for (int i = 0; i < RUNS; i++) - x += Math.sin(i / 1000000.0); + x += Math.sin(i * F1); long mathTime = System.nanoTime() - time; report("sin",strictTime,fastTime,mathTime); @@ -175,19 +223,19 @@ public class FastMathTestPerformance { double x = 0; long time = System.nanoTime(); for (int i = 0; i < RUNS; i++) - x += StrictMath.cos(i / 1000000.0); + x += StrictMath.cos(i * F1); long strictTime = System.nanoTime() - time; x = 0; time = System.nanoTime(); for (int i = 0; i < RUNS; i++) - x += FastMath.cos(i / 1000000.0); + x += FastMath.cos(i * F1); long fastTime = System.nanoTime() - time; x = 0; time = System.nanoTime(); for (int i = 0; i < RUNS; i++) - x += Math.cos(i / 1000000.0); + x += Math.cos(i * F1); long mathTime = System.nanoTime() - time; report("cos",strictTime,fastTime,mathTime); @@ -220,19 +268,19 @@ public class FastMathTestPerformance { double x = 0; long time = System.nanoTime(); for (int i = 0; i < RUNS; i++) - x += StrictMath.tan(i / 1000000.0); + x += StrictMath.tan(i * F1); long strictTime = System.nanoTime() - time; x = 0; time = System.nanoTime(); for (int i = 0; i < RUNS; i++) - x += FastMath.tan(i / 1000000.0); + x += FastMath.tan(i * F1); long fastTime = System.nanoTime() - time; x = 0; time = System.nanoTime(); for (int i = 0; i < RUNS; i++) - x += Math.tan(i / 1000000.0); + x += Math.tan(i * F1); long mathTime = System.nanoTime() - time; report("tan",strictTime,fastTime,mathTime); @@ -243,65 +291,134 @@ public class FastMathTestPerformance { double x = 0; long time = System.nanoTime(); for (int i = 0; i < RUNS; i++) - x += StrictMath.atan(i / 1000000.0); + x += StrictMath.atan(i * F1); long strictTime = System.nanoTime() - time; x = 0; time = System.nanoTime(); for (int i = 0; i < RUNS; i++) - x += FastMath.atan(i / 1000000.0); + x += FastMath.atan(i * F1); long fastTime = System.nanoTime() - time; x = 0; time = System.nanoTime(); for (int i = 0; i < RUNS; i++) - x += Math.atan(i / 1000000.0); + x += Math.atan(i * F1); long mathTime = System.nanoTime() - time; report("atan",strictTime,fastTime,mathTime); } + + @Test + public void testAtan2() { + double x = 0; + long time = System.nanoTime(); + for (int i = 0; i < RUNS; i++) + x += StrictMath.atan2(i * F1, i * F1); + long strictTime = System.nanoTime() - time; + + x = 0; + time = System.nanoTime(); + for (int i = 0; i < RUNS; i++) + x += FastMath.atan2(i * F1, i * F1); + long fastTime = System.nanoTime() - time; + + x = 0; + time = System.nanoTime(); + for (int i = 0; i < RUNS; i++) + x += Math.atan2(i * F1, i * F1); + long mathTime = System.nanoTime() - time; + + report("atan2",strictTime,fastTime,mathTime); + } + + @Test + public void testHypot() { + double x = 0; + long time = System.nanoTime(); + for (int i = 0; i < RUNS; i++) + x += StrictMath.hypot(i * F1, i * F1); + long strictTime = System.nanoTime() - time; + + x = 0; + time = System.nanoTime(); + for (int i = 0; i < RUNS; i++) + x += FastMath.hypot(i * F1, i * F1); + long fastTime = System.nanoTime() - time; + + x = 0; + time = System.nanoTime(); + for (int i = 0; i < RUNS; i++) + x += Math.hypot(i * F1, i * F1); + long mathTime = System.nanoTime() - time; + + report("hypot",strictTime,fastTime,mathTime); + } @Test public void testCbrt() { double x = 0; long time = System.nanoTime(); for (int i = 0; i < RUNS; i++) - x += StrictMath.cbrt(i / 1000000.0); + x += StrictMath.cbrt(i * F1); long strictTime = System.nanoTime() - time; x = 0; time = System.nanoTime(); for (int i = 0; i < RUNS; i++) - x += FastMath.cbrt(i / 1000000.0); + x += FastMath.cbrt(i * F1); long fastTime = System.nanoTime() - time; x = 0; time = System.nanoTime(); for (int i = 0; i < RUNS; i++) - x += Math.cbrt(i / 1000000.0); + x += Math.cbrt(i * F1); long mathTime = System.nanoTime() - time; report("cbrt",strictTime,fastTime,mathTime); } @Test + public void testSqrt() { + double x = 0; + long time = System.nanoTime(); + for (int i = 0; i < RUNS; i++) + x += StrictMath.sqrt(i * F1); + long strictTime = System.nanoTime() - time; + + x = 0; + time = System.nanoTime(); + for (int i = 0; i < RUNS; i++) + x += FastMath.sqrt(i * F1); + long fastTime = System.nanoTime() - time; + + x = 0; + time = System.nanoTime(); + for (int i = 0; i < RUNS; i++) + x += Math.sqrt(i * F1); + long mathTime = System.nanoTime() - time; + + report("sqrt",strictTime,fastTime,mathTime); + } + + @Test public void testCosh() { double x = 0; long time = System.nanoTime(); for (int i = 0; i < RUNS; i++) - x += StrictMath.cosh(i / 1000000.0); + x += StrictMath.cosh(i * F1); long strictTime = System.nanoTime() - time; x = 0; time = System.nanoTime(); for (int i = 0; i < RUNS; i++) - x += FastMath.cosh(i / 1000000.0); + x += FastMath.cosh(i * F1); long fastTime = System.nanoTime() - time; x = 0; time = System.nanoTime(); for (int i = 0; i < RUNS; i++) - x += Math.cosh(i / 1000000.0); + x += Math.cosh(i * F1); long mathTime = System.nanoTime() - time; report("cosh",strictTime,fastTime,mathTime); @@ -312,19 +429,19 @@ public class FastMathTestPerformance { double x = 0; long time = System.nanoTime(); for (int i = 0; i < RUNS; i++) - x += StrictMath.sinh(i / 1000000.0); + x += StrictMath.sinh(i * F1); long strictTime = System.nanoTime() - time; x = 0; time = System.nanoTime(); for (int i = 0; i < RUNS; i++) - x += FastMath.sinh(i / 1000000.0); + x += FastMath.sinh(i * F1); long fastTime = System.nanoTime() - time; x = 0; time = System.nanoTime(); for (int i = 0; i < RUNS; i++) - x += Math.sinh(i / 1000000.0); + x += Math.sinh(i * F1); long mathTime = System.nanoTime() - time; report("sinh",strictTime,fastTime,mathTime); @@ -335,19 +452,19 @@ public class FastMathTestPerformance { double x = 0; long time = System.nanoTime(); for (int i = 0; i < RUNS; i++) - x += StrictMath.tanh(i / 1000000.0); + x += StrictMath.tanh(i * F1); long strictTime = System.nanoTime() - time; x = 0; time = System.nanoTime(); for (int i = 0; i < RUNS; i++) - x += FastMath.tanh(i / 1000000.0); + x += FastMath.tanh(i * F1); long fastTime = System.nanoTime() - time; x = 0; time = System.nanoTime(); for (int i = 0; i < RUNS; i++) - x += Math.tanh(i / 1000000.0); + x += Math.tanh(i * F1); long mathTime = System.nanoTime() - time; report("tanh",strictTime,fastTime,mathTime); @@ -358,20 +475,43 @@ public class FastMathTestPerformance { double x = 0; long time = System.nanoTime(); for (int i = 0; i < RUNS; i++) - x += StrictMath.expm1(-i / 100000.0); + x += StrictMath.expm1(-i * F1); long strictTime = System.nanoTime() - time; x = 0; time = System.nanoTime(); for (int i = 0; i < RUNS; i++) - x += FastMath.expm1(-i / 100000.0); + x += FastMath.expm1(-i * F1); long fastTime = System.nanoTime() - time; x = 0; time = System.nanoTime(); for (int i = 0; i < RUNS; i++) - x += Math.expm1(-i / 100000.0); + x += Math.expm1(-i * F1); long mathTime = System.nanoTime() - time; report("expm1",strictTime,fastTime,mathTime); } + + @Test + public void testAbs() { + double x = 0; + long time = System.nanoTime(); + for (int i = 0; i < RUNS; i++) + x += StrictMath.abs(i * (1 - 0.5 * RUNS)); + long strictTime = System.nanoTime() - time; + + x = 0; + time = System.nanoTime(); + for (int i = 0; i < RUNS; i++) + x += FastMath.abs(i * (1 - 0.5 * RUNS)); + long fastTime = System.nanoTime() - time; + + x = 0; + time = System.nanoTime(); + for (int i = 0; i < RUNS; i++) + x += Math.abs(i * (1 - 0.5 * RUNS)); + long mathTime = System.nanoTime() - time; + + report("abs",strictTime,fastTime,mathTime); + } }