summaryrefslogtreecommitdiff
path: root/test/bench
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2009-08-10 17:44:46 -0700
committerRobert Griesemer <gri@golang.org>2009-08-10 17:44:46 -0700
commit22acfd4de12a99578303745d589667a6be1e4e8a (patch)
treebfac2042b0ef21bf6785cb0395c570c79e500092 /test/bench
parentbb652ff00afdc59a30ba3dc58121e3ae4afc6bb7 (diff)
downloadgo-22acfd4de12a99578303745d589667a6be1e4e8a.tar.gz
- use in-place bignum operations where available
- runs approx. 30% faster R=r DELTA=24 (10 added, 2 deleted, 12 changed) OCL=32984 CL=33005
Diffstat (limited to 'test/bench')
-rw-r--r--test/bench/pidigits.go29
-rw-r--r--test/bench/timing.log7
2 files changed, 22 insertions, 14 deletions
diff --git a/test/bench/pidigits.go b/test/bench/pidigits.go
index 6e1e7e053..b02c6e79e 100644
--- a/test/bench/pidigits.go
+++ b/test/bench/pidigits.go
@@ -44,8 +44,6 @@ import (
)
var n = flag.Int("n", 27, "number of digits");
-
-// TODO for easier profiling, remove eventually
var silent = flag.Bool("s", false, "don't print result");
var (
@@ -61,13 +59,16 @@ func extract_digit() int64 {
return -1;
}
- /* Compute (numer * 3 + accum) / denom */
- tmp1, tmp2 = numer.MulNat(bignum.Nat(3)).Add(accum).QuoRem(denom);
+ // Compute (numer * 3 + accum) / denom
+ tmp1 = numer.Shl(1);
+ bignum.Iadd(tmp1, tmp1, numer);
+ bignum.Iadd(tmp1, tmp1, accum);
+ tmp1, tmp2 := tmp1.QuoRem(denom);
- /* Now, if (numer * 4 + accum) % denom... */
- tmp2 = tmp2.Add(numer);
+ // Now, if (numer * 4 + accum) % denom...
+ bignum.Iadd(tmp2, tmp2, numer);
- /* ... is normalized, then the two divisions have the same result. */
+ // ... is normalized, then the two divisions have the same result.
if tmp2.Cmp(denom) >= 0 {
return -1;
}
@@ -79,16 +80,16 @@ func next_term(k int64) {
y2 := k*2 + 1;
tmp1 = numer.Shl(1);
- accum = accum.Add(tmp1);
- accum = accum.Mul1(y2);
- numer = numer.Mul1(k);
- denom = denom.Mul1(y2);
+ bignum.Iadd(accum, accum, tmp1);
+ bignum.Iscale(accum, y2);
+ bignum.Iscale(numer, k);
+ bignum.Iscale(denom, y2);
}
func eliminate_digit(d int64) {
- accum = accum.Sub(denom.Mul1(d));
- accum = accum.Mul1(10);
- numer = numer.Mul1(10);
+ bignum.Isub(accum, accum, denom.Mul1(d));
+ bignum.Iscale(accum, 10);
+ bignum.Iscale(numer, 10);
}
func printf(s string, arg ...) {
diff --git a/test/bench/timing.log b/test/bench/timing.log
index e73d061b1..75c92f26e 100644
--- a/test/bench/timing.log
+++ b/test/bench/timing.log
@@ -231,3 +231,10 @@ chameneos 6000000
gcc -O2 chameneosredux.c -lpthread 17.93u 323.65s 88.47r
gc chameneosredux 21.72u 0.00s 21.73r
+August 10 2009
+
+# In-place versions for some bignum operations.
+pidigits 10000
+ gcc -O2 pidigits.c -lgmp 2.56u 0.00s 2.57r
+ gc pidigits 55.22u 0.04s 55.29r # *** -23%
+ gc_B pidigits 55.49u 0.02s 55.60r # *** -23%