mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-03-17 21:31:57 +01:00
Separates the random benchmark from the Sign/Verify benchmarks
This commit is contained in:
parent
9c35008fc4
commit
8720b00d4f
@ -0,0 +1,50 @@
|
||||
/**
|
||||
* Copyright (c) 2024 Vitor Pamplona
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package com.vitorpamplona.quartz.benchmark
|
||||
|
||||
import androidx.benchmark.junit4.BenchmarkRule
|
||||
import androidx.benchmark.junit4.measureRepeated
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.vitorpamplona.quartz.utils.RandomInstance
|
||||
import junit.framework.TestCase.assertNotNull
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class RandomBenchmark {
|
||||
@get:Rule val benchmarkRule = BenchmarkRule()
|
||||
|
||||
@Test
|
||||
fun random32Bytes() {
|
||||
benchmarkRule.measureRepeated { assertNotNull(RandomInstance.bytes(32)) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun random1000Bytes() {
|
||||
benchmarkRule.measureRepeated { assertNotNull(RandomInstance.bytes(1000)) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun randomInt() {
|
||||
benchmarkRule.measureRepeated { assertNotNull(RandomInstance.int(1000)) }
|
||||
}
|
||||
}
|
@ -28,6 +28,7 @@ import com.vitorpamplona.quartz.nip01Core.crypto.Nip01
|
||||
import com.vitorpamplona.quartz.utils.RandomInstance
|
||||
import com.vitorpamplona.quartz.utils.sha256.sha256
|
||||
import junit.framework.TestCase.assertNotNull
|
||||
import junit.framework.TestCase.assertTrue
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
@ -36,11 +37,6 @@ import org.junit.runner.RunWith
|
||||
class SignVerifyBenchmark {
|
||||
@get:Rule val benchmarkRule = BenchmarkRule()
|
||||
|
||||
@Test
|
||||
fun random() {
|
||||
benchmarkRule.measureRepeated { assertNotNull(RandomInstance.bytes(1000)) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun sign() {
|
||||
val keyPair = KeyPair()
|
||||
@ -56,7 +52,7 @@ class SignVerifyBenchmark {
|
||||
val signature = Nip01.sign(msg, keyPair.privKey!!)
|
||||
|
||||
benchmarkRule.measureRepeated {
|
||||
assertNotNull(Nip01.verify(signature, msg, keyPair.pubKey))
|
||||
assertTrue(Nip01.verify(signature, msg, keyPair.pubKey))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user