Added Benchmark_RandomX
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
8db94fb12b
commit
38b0377f45
|
@ -29,11 +29,12 @@ 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
|
||||
|
@ -46,6 +47,8 @@ func Test_Randomx(t *testing.T) {
|
|||
{[]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)
|
||||
|
||||
for ix, tt := range Tests {
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Reference in a new issue