Added Benchmark_RandomX
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
DataHoarder 2024-04-11 10:24:12 +02:00
parent 8db94fb12b
commit 38b0377f45
Signed by: DataHoarder
SSH key fingerprint: SHA256:OLTRf6Fl87G52SiR7sWLGNzlJt4WOX+tfI2yxo0z7xk
2 changed files with 41 additions and 13 deletions

View file

@ -29,22 +29,25 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package randomx
import "fmt"
import (
"fmt"
"runtime"
)
import "testing"
func Test_Randomx(t *testing.T) {
var Tests = []struct {
key []byte // key
input []byte // input
expected string // expected result
}{
{[]byte("RandomX example key\x00"), []byte("RandomX example input\x00"), "8a48e5f9db45ab79d9080574c4d81954fe6ac63842214aff73c244b26330b7c9"},
{[]byte("test key 000"), []byte("This is a test"), "639183aae1bf4c9a35884cb46b09cad9175f04efd7684e7262a0ac1c2f0b4e3f"}, // test a
{[]byte("test key 000"), []byte("Lorem ipsum dolor sit amet"), "300a0adb47603dedb42228ccb2b211104f4da45af709cd7547cd049e9489c969"}, // test b
{[]byte("test key 000"), []byte("sed do eiusmod tempor incididunt ut labore et dolore magna aliqua"), "c36d4ed4191e617309867ed66a443be4075014e2b061bcdaf9ce7b721d2b77a8"}, // test c
{[]byte("test key 001"), []byte("sed do eiusmod tempor incididunt ut labore et dolore magna aliqua"), "e9ff4503201c0c2cca26d285c93ae883f9b1d30c9eb240b820756f2d5a7905fc"}, // test d
}
var Tests = []struct {
key []byte // key
input []byte // input
expected string // expected result
}{
{[]byte("RandomX example key\x00"), []byte("RandomX example input\x00"), "8a48e5f9db45ab79d9080574c4d81954fe6ac63842214aff73c244b26330b7c9"},
{[]byte("test key 000"), []byte("This is a test"), "639183aae1bf4c9a35884cb46b09cad9175f04efd7684e7262a0ac1c2f0b4e3f"}, // test a
{[]byte("test key 000"), []byte("Lorem ipsum dolor sit amet"), "300a0adb47603dedb42228ccb2b211104f4da45af709cd7547cd049e9489c969"}, // test b
{[]byte("test key 000"), []byte("sed do eiusmod tempor incididunt ut labore et dolore magna aliqua"), "c36d4ed4191e617309867ed66a443be4075014e2b061bcdaf9ce7b721d2b77a8"}, // test c
{[]byte("test key 001"), []byte("sed do eiusmod tempor incididunt ut labore et dolore magna aliqua"), "e9ff4503201c0c2cca26d285c93ae883f9b1d30c9eb240b820756f2d5a7905fc"}, // test d
}
func Test_Randomx(t *testing.T) {
c := Randomx_alloc_cache(0)
@ -71,3 +74,27 @@ func Test_Randomx(t *testing.T) {
}
}
func Benchmark_RandomX(b *testing.B) {
b.ReportAllocs()
tt := Tests[0]
c := Randomx_alloc_cache(0)
c.Randomx_init_cache(tt.key)
nonce := uint32(0) //uint32(len(key))
gen := Init_Blake2Generator(tt.key, nonce)
for i := 0; i < 8; i++ {
c.Programs[i] = Build_SuperScalar_Program(gen) // build a superscalar program
}
vm := c.VM_Initialize()
b.ResetTimer()
for i := 0; i < b.N; i++ {
var output_hash [32]byte
vm.CalculateHash(tt.input, output_hash[:])
runtime.KeepAlive(output_hash)
}
}

View file

@ -917,6 +917,7 @@ func (cache *Randomx_Cache) InitDatasetItem(out []uint64, itemnumber uint64) {
cache.Programs[i].executeSuperscalar_nocache(rl[:])
cache.GetBlock(register_value, mix_block)
//TODO: this can be optimized with xorBytes
for q := range rl {
// fmt.Printf("%d rl[%d] %16x mix %16x\n",i, q,rl[q], mix_block[q])
rl[q] ^= mix_block[q]