Skip to content

Commit

Permalink
Revise all of the output to use ufmt.
Browse files Browse the repository at this point in the history
  • Loading branch information
wyhaines committed Sep 28, 2024
1 parent 08fb337 commit cd29bf1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 30 deletions.
19 changes: 10 additions & 9 deletions examples/gno.land/p/demo/math/rand/isaac/isaac.gno
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ package isaac

import (
"errors"
"fmt"
"math"

"gno.land/p/demo/entropy"
"gno.land/p/demo/math/rand/xorshiftr128plus"
"gno.land/p/demo/ufmt"
)

type ISAAC struct {
Expand Down Expand Up @@ -356,7 +356,7 @@ func benchmarkISAAC(_iterations ...int) {
for i := 0; i < iterations; i++ {
_ = isaac.Uint64()
}
fmt.Printf("ISAAC: generate %d uint64\n", iterations)
ufmt.Println(ufmt.Sprintf("ISAAC: generate %d uint64\n", iterations))
}

// The averageISAAC() function is a simple benchmarking helper to demonstrate
Expand All @@ -366,10 +366,11 @@ func averageISAAC(_iterations ...int) {
iterations := 1000000
var squares [1000000]uint64

fmt.Printf(
"Averaging %d random numbers. The average should be very close to %d.\n",
iterations,
target)
ufmt.Println(
ufmt.Sprintf(
"Averaging %d random numbers. The average should be very close to %d.\n",
iterations,
target))

if len(_iterations) > 0 {
iterations = _iterations[0]
Expand All @@ -391,7 +392,7 @@ func averageISAAC(_iterations ...int) {
sum_of_squares += square
}

fmt.Printf("ISAAC average of %d uint64: %f\n", iterations, average)
fmt.Printf("ISAAC standard deviation : %f\n", math.Sqrt(float64(sum_of_squares)/float64(iterations)))
fmt.Printf("ISAAC theoretical perfect deviation: %f\n", (float64(target*2)-1)/math.Sqrt(12))
ufmt.Println(ufmt.Sprintf("ISAAC average of %d uint64: %f\n", iterations, average))
ufmt.Println(ufmt.Sprintf("ISAAC standard deviation : %f\n", math.Sqrt(float64(sum_of_squares)/float64(iterations))))
ufmt.Println(ufmt.Sprintf("ISAAC theoretical perfect deviation: %f\n", (float64(target*2)-1)/math.Sqrt(12)))
}
23 changes: 12 additions & 11 deletions examples/gno.land/p/demo/math/rand/isaac64/isaac64.gno
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
// ---------
// PCG: 1000000 Uint64 generated in 15.58s
// ISAAC: 1000000 Uint64 generated in 8.95s
// ISAAC: 1000000 Uint32 generated in 7.66s
// ISAAC: 1000000 Uint32 generated in 7.66s
// Ratio: x1.74 times faster than PCG (uint64)
// Ratio: x2.03 times faster than PCG (uint32)
// Ratio: x2.03 times faster than PCG (uint32)
//
// Use it directly:
//
Expand All @@ -41,11 +41,11 @@ package isaac64

import (
"errors"
"fmt"
"math"

"gno.land/p/demo/entropy"
"gno.land/p/demo/math/rand/xorshiftr128plus"
"gno.land/p/demo/ufmt"
)

const (
Expand Down Expand Up @@ -387,7 +387,7 @@ func benchmarkISAAC(_iterations ...int) {
for i := 0; i < iterations; i++ {
_ = isaac.Uint64()
}
fmt.Printf("ISAAC: generated %d uint64\n", iterations)
ufmt.Println(ufmt.Sprintf("ISAAC: generated %d uint64\n", iterations))
}

// The averageISAAC() function is a simple benchmarking helper to demonstrate
Expand All @@ -396,10 +396,11 @@ func averageISAAC(_iterations ...int) {
target := uint64(500000)
iterations := 1000000

fmt.Printf(
"Averaging %d random numbers. The average should be very close to %d.\n",
iterations,
target)
ufmt.Println(
ufmt.Sprintf(
"Averaging %d random numbers. The average should be very close to %d.\n",
iterations,
target))

if len(_iterations) > 0 {
iterations = _iterations[0]
Expand All @@ -422,7 +423,7 @@ func averageISAAC(_iterations ...int) {
sum_of_squares += square
}

fmt.Printf("ISAAC average of %d uint64: %f\n", iterations, average)
fmt.Printf("ISAAC standard deviation : %f\n", math.Sqrt(float64(sum_of_squares)/float64(iterations)))
fmt.Printf("ISAAC theoretical perfect deviation: %f\n", (float64(target*2)-1)/math.Sqrt(12))
ufmt.Println(ufmt.Sprintf("ISAAC average of %d uint64: %f\n", iterations, average))
ufmt.Println(ufmt.Sprintf("ISAAC standard deviation : %f\n", math.Sqrt(float64(sum_of_squares)/float64(iterations))))
ufmt.Println(ufmt.Sprintf("ISAAC theoretical perfect deviation: %f\n", (float64(target*2)-1)/math.Sqrt(12)))
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ package xorshift64star

import (
"errors"
"fmt"
"math"

"gno.land/p/demo/entropy"
"gno.land/p/demo/ufmt"
)

// Xorshift64Star is a PRNG that implements the Xorshift64* algorithm.
Expand Down Expand Up @@ -130,7 +130,7 @@ func benchmarkXorshift64Star(_iterations ...int) {
for i := 0; i < iterations; i++ {
_ = xs64s.Uint64()
}
fmt.Printf("Xorshift64*: generate %d uint64\n", iterations)
ufmt.Println(ufmt.Sprintf("Xorshift64*: generate %d uint64\n", iterations))
}

// The averageXorshift64Star() function is a simple benchmarking helper to demonstrate
Expand All @@ -140,10 +140,11 @@ func averageXorshift64Star(_iterations ...int) {
iterations := 1000000
var squares [1000000]uint64

fmt.Printf(
"Averaging %d random numbers. The average should be very close to %d.\n",
iterations,
target)
ufmt.Println(
ufmt.Sprintf(
"Averaging %d random numbers. The average should be very close to %d.\n",
iterations,
target))

if len(_iterations) > 0 {
iterations = _iterations[0]
Expand All @@ -165,7 +166,7 @@ func averageXorshift64Star(_iterations ...int) {
sum_of_squares += square
}

fmt.Printf("Xorshift64* average of %d uint64: %f\n", iterations, average)
fmt.Printf("Xorshift64* standard deviation : %f\n", math.Sqrt(float64(sum_of_squares)/float64(iterations)))
fmt.Printf("Xorshift64* theoretical perfect deviation: %f\n", (float64(target*2)-1)/math.Sqrt(12))
ufmt.Println(ufmt.Sprintf("Xorshift64* average of %d uint64: %f\n", iterations, average))
ufmt.Println(ufmt.Sprintf("Xorshift64* standard deviation : %f\n", math.Sqrt(float64(sum_of_squares)/float64(iterations))))
ufmt.Println(ufmt.Sprintf("Xorshift64* theoretical perfect deviation: %f\n", (float64(target*2)-1)/math.Sqrt(12)))
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import (
"errors"
"math"

"gno.land/p/demo/ufmt"
"gno.land/p/demo/entropy"
"gno.land/p/demo/ufmt"
)

type Xorshiftr128Plus struct {
Expand Down

0 comments on commit cd29bf1

Please sign in to comment.