pub struct RandomxVm<'a, T: 'a> { /* private fields */ }Implementations§
Source§impl RandomxVm<'_, RandomxCache>
impl RandomxVm<'_, RandomxCache>
pub fn new( flags: RandomxFlags, cache: &RandomxCache, ) -> Result<Self, RandomxError>
Source§impl RandomxVm<'_, RandomxDataset>
impl RandomxVm<'_, RandomxDataset>
Sourcepub fn new_fast(
flags: RandomxFlags,
dataset: &RandomxDataset,
) -> Result<Self, RandomxError>
pub fn new_fast( flags: RandomxFlags, dataset: &RandomxDataset, ) -> Result<Self, RandomxError>
Examples found in repository?
examples/multithreaded.rs (line 32)
10fn main() {
11 const NUM_THREADS: u32 = 8;
12 // number of hashes to perform in each thread, not the total.
13 const NUM_HASHES: u32 = 5000;
14
15 let start = Instant::now();
16
17 // Try adding `| RandomxFlags::LARGEPAGES`.
18 let flags = RandomxFlags::default() | RandomxFlags::FULLMEM;
19 let dataset = Arc::new(RandomxDataset::new(flags, b"key", NUM_THREADS as u8).unwrap());
20
21 println!("Dataset initialised in {}ms", start.elapsed().as_millis());
22
23 let mut handles = Vec::new();
24
25 let start = Instant::now();
26
27 for i in 0..NUM_THREADS {
28 let dataset = dataset.clone();
29
30 handles.push(thread::spawn(move || {
31 let mut nonce: u32 = i;
32 let vm = RandomxVm::new_fast(flags, &dataset).unwrap();
33
34 for _ in 0..NUM_HASHES {
35 let _ = vm.hash(&nonce.to_be_bytes());
36
37 // e.g. thread 0 will use nonces 0, 8, 16, ...
38 // and thread 1 will use nonces 1, 9, 17, ...
39 nonce += NUM_THREADS;
40 }
41 }));
42 }
43
44 for handle in handles {
45 let _ = handle.join();
46 }
47
48 println!(
49 "Completed {} hashes in {}ms",
50 NUM_THREADS * NUM_HASHES,
51 start.elapsed().as_millis()
52 );
53}Source§impl<T> RandomxVm<'_, T>
impl<T> RandomxVm<'_, T>
Sourcepub fn hash(&self, input: &[u8]) -> [u8; 32]
pub fn hash(&self, input: &[u8]) -> [u8; 32]
Calculate the RandomX hash of some data.
use randomx_bindings::*;
let flags = RandomxFlags::default();
let cache = RandomxCache::new(flags, "key".as_bytes())?;
let vm = RandomxVm::new(flags, &cache)?;
let hash = vm.hash("input".as_bytes());Examples found in repository?
examples/multithreaded.rs (line 35)
10fn main() {
11 const NUM_THREADS: u32 = 8;
12 // number of hashes to perform in each thread, not the total.
13 const NUM_HASHES: u32 = 5000;
14
15 let start = Instant::now();
16
17 // Try adding `| RandomxFlags::LARGEPAGES`.
18 let flags = RandomxFlags::default() | RandomxFlags::FULLMEM;
19 let dataset = Arc::new(RandomxDataset::new(flags, b"key", NUM_THREADS as u8).unwrap());
20
21 println!("Dataset initialised in {}ms", start.elapsed().as_millis());
22
23 let mut handles = Vec::new();
24
25 let start = Instant::now();
26
27 for i in 0..NUM_THREADS {
28 let dataset = dataset.clone();
29
30 handles.push(thread::spawn(move || {
31 let mut nonce: u32 = i;
32 let vm = RandomxVm::new_fast(flags, &dataset).unwrap();
33
34 for _ in 0..NUM_HASHES {
35 let _ = vm.hash(&nonce.to_be_bytes());
36
37 // e.g. thread 0 will use nonces 0, 8, 16, ...
38 // and thread 1 will use nonces 1, 9, 17, ...
39 nonce += NUM_THREADS;
40 }
41 }));
42 }
43
44 for handle in handles {
45 let _ = handle.join();
46 }
47
48 println!(
49 "Completed {} hashes in {}ms",
50 NUM_THREADS * NUM_HASHES,
51 start.elapsed().as_millis()
52 );
53}Trait Implementations§
Auto Trait Implementations§
impl<'a, T> Freeze for RandomxVm<'a, T>
impl<'a, T> RefUnwindSafe for RandomxVm<'a, T>where
T: RefUnwindSafe,
impl<'a, T> !Sync for RandomxVm<'a, T>
impl<'a, T> Unpin for RandomxVm<'a, T>
impl<'a, T> UnwindSafe for RandomxVm<'a, T>where
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more