Skip to content

Commit

Permalink
more misc. code cleanup; update benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
ericlagergren committed Apr 8, 2019
1 parent 1d7183f commit ac8aeb4
Show file tree
Hide file tree
Showing 18 changed files with 89 additions and 376 deletions.
53 changes: 0 additions & 53 deletions benchmarks/README.md

This file was deleted.

69 changes: 69 additions & 0 deletions benchmarks/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Package benchmarks implements benchmarking across decimal packages.
//
// General Notes
//
// 1. Times are measured in seconds, unless otherwise noted
// 2. Measured on a MacBook Pro, 2.9 GHz Intel Core i5, 8 GB 2133 MHz LPDDR3
// 3. Some benchmarks are adapted from www.bytereef.org/mpdecimal/benchmarks.html
//
// While the benchmarks aim to be as fair as possible, the packages have
// different feature sets and objects.
//
// For example, go-inf/inf[8] boasts the fastest overall runtime of any package,
// but does not fully implement the GDA specification: it lacks contexts,
// non-finite values (NaN, Inf, or ±0), conditions, etc.
//
// Further, programs like cockroachdb/apd[2] sacrifice speed to ensure strict
// compliance with the GDA spec.
//
// In general, package sthat cannot fully complete a challenge will be unranked.
// For example, the ``float64'' type cannot provide 19 or more digits of precision,
// so it's unranked in the Pi test. Similarly so with apmckinlay/dnum[3].
//
// Pi
//
// Go programs are tested with Go 1.12.2.
//
// Java benchmarks are separated into two categories, warm and cold. Warm
// benchmarks are run 10,000 times prior to benchmarking.
//
// | Program (version) | 9 digits | 19 digits | 38 digits | 100 digits | average |
// |--------------------------------------|----------|-----------|-----------|------------|---------|
// | go-inf/inf[8] | 0.241 | 0.537 | 1.12 | 3.01 | 1.227 |
// | ericlagergren/decimal[1] (mode Go) | 0.142 | 0.639 | 1.46 | 4.16 | 1.60 |
// | Python decimal[5] (Python 3.7.3) | 0.38 | 0.791 | 1.77 | 6.21 | 2.29 |
// | JDK BigDecimal[4] (Java 1.8, warm) | 0.156 | 0.717 | 1.957 | 7.252 | 2.52 |
// | ericlagergren/decimal[1] (mode GDA) | 0.204 | 0.953 | 2.37 | 8.40 | 2.98 |
// | JDK BigDecimal[4] (Java 1.8, cold) | 0.532 | 1.638 | 3.413 | 7.747 | 3.332 |
// | shopspring/decimal[7] decimal | 0.83 | 1.78 | 4.00 | 10.90 | 4.37 |
// | cockroachdb/apd[2] | 1.54 | 7.50 | 43.6 | 237.00 | 72.41 |
// | Python decimal[6] (Python 2.7.10) | 31.81 | 74.502 | 161.71 | 460.00 | 182.00 |
// | float64 | 0.125 | - | - | - | - |
// | double (C LLVM 10.0.1 -O3) | 0.0589 | - | - | - | - |
// | apmckinlay/dnum[3] | 0.078 | - | - | - | - |
// | float (Python 2.7.10, 3.7.3) | 0.0923 | - | - | - | - |
//
// Mandelbrot
//
// Go programs are tested with Go 1.9.?.
//
// | Program (version) | 9 digits | 16 digits | 19 digits | 34 digits | 38 digits | average |
// |--------------------------------------|----------|-----------|-----------|-----------|-----------|---------|
// | ericlagergren/decimal[1] (mode GDA) | 2.73 | 9.07 | 14.54 | 24.95 | 25.09 | 15.27 |
// | ericlagergren/decimal[1] (mode Go) | 2.73 | 9.70 | 15.02 | 26.13 | 26.62 | 16.04 |
// | float64 | 0.0034 | - | - | - | - | - |
//
// References
//
// Further information and references can be found at the links below.
//
// [1]: github.com/ericlagergren/decimal
// [2]: github.com/cockroachdb/apd
// [3]: github.com/apmckinlay/gsuneido/util/dnum
// [4]: docs.oracle.com/javase/8/docs/api/java/math/BigDecimal.html
// [5]: docs.python.org/3.6/library/decimal.html
// [6]: docs.python.org/2/library/decimal.html
// [7]: github.com/shopspring/decimal
// [8]: github.com/go-inf/inf
//
package benchmarks
4 changes: 1 addition & 3 deletions benchmarks/mandelbrot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import (

const mbrotiters = 10000000

var (
two = decimal.New(2, 0)
)
var two = decimal.New(2, 0)

func BenchmarkMandelbrot_float64(b *testing.B) {
var lf float64
Expand Down
1 change: 0 additions & 1 deletion benchmarks/pi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ func calcPiGDA(prec int) *decimal.Big {
ctx.Add(s, s, t)
}
return s.Round(prec)

}

func calcPi_apd(prec uint32) *apd.Decimal {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ int main(void) {
for (int j = 0; j < ROUNDS; ++j) {
ld = calcPifloat();
}
sum += (double)(clock() - start_clock)/(double)(CLOCKS_PER_SEC);
sum += (double)(clock() - start_clock) / (double)(CLOCKS_PER_SEC);
}
gd = ld;
printf("average: %f\n", sum / NITER);
Expand Down
11 changes: 11 additions & 0 deletions benchmarks/testdata/java/java.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static void main(String... args) {
throw new IllegalArgumentException("bad argument " + args);
}

for (int i = 0; i < 10000; ++i) {
for (int i = 0; i < 0; ++i) {
r = fn.apply(new MathContext(precs[i % precs.length]));
}

Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion big.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,6 @@ func (x *Big) Format(s fmt.State, c rune) {
if !hasPrec {
prec = 0
} else {

// %f's precision means "number of digits after the radix"
if x.exp > 0 {
f.prec += x.Precision()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/ericlagergren/decimal

require (
github.com/apmckinlay/gsuneido v0.0.0-20180907175622-1f10244968e3
github.com/apmckinlay/gsuneido v0.0.0-20190404155041-0b6cd442a18f
github.com/cockroachdb/apd v1.1.0
github.com/lib/pq v1.0.0 // indirect
github.com/pkg/errors v0.8.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/apmckinlay/gsuneido v0.0.0-20180907175622-1f10244968e3 h1:GGt+2fBzp83fE4DGSstL0K/crfQyXu7qOEKrvnwJRtU=
github.com/apmckinlay/gsuneido v0.0.0-20180907175622-1f10244968e3/go.mod h1:hJnaqxrCRgMCTWtpNz9XUFkBCREiQdlcyK6YNmOfroM=
github.com/apmckinlay/gsuneido v0.0.0-20190404155041-0b6cd442a18f h1:WwxMm9boNuaj5YW+qfRoORxLLJrSRiK1zovCfGNddY0=
github.com/apmckinlay/gsuneido v0.0.0-20190404155041-0b6cd442a18f/go.mod h1:JU2DOj5Fc6rol0yaT79Csr47QR0vONGwJtBNGRD7jmc=
github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I=
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A=
Expand Down
4 changes: 1 addition & 3 deletions math/arccosine.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package math

import (
"github.com/ericlagergren/decimal"
)
import "github.com/ericlagergren/decimal"

// Acos returns the arccosine, in radians, of x.
//
Expand Down
4 changes: 1 addition & 3 deletions math/sqrt.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package math

import (
"github.com/ericlagergren/decimal"
)
import "github.com/ericlagergren/decimal"

// Hypot sets z to Sqrt(p*p + q*q) and returns z.
func Hypot(z, p, q *decimal.Big) *decimal.Big {
Expand Down
130 changes: 0 additions & 130 deletions suite/getcases.go

This file was deleted.

Binary file removed suite/ieee-test-suite-v2.pdf
Binary file not shown.
Loading

0 comments on commit ac8aeb4

Please sign in to comment.