This repository has been archived by the owner on Jan 10, 2025. It is now read-only.
forked from qmonnet/rbpf
-
Notifications
You must be signed in to change notification settings - Fork 180
/
Copy pathjit_compile.rs
53 lines (48 loc) · 1.6 KB
/
jit_compile.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2020 Solana Maintainers <[email protected]>
//
// Licensed under the Apache License, Version 2.0 <http://www.apache.org/licenses/LICENSE-2.0> or
// the MIT license <http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.
#![feature(test)]
extern crate solana_rbpf;
extern crate test;
use solana_rbpf::{
elf::Executable,
user_error::UserError,
vm::{Config, EbpfVm, SyscallRegistry, TestInstructionMeter},
};
use std::{fs::File, io::Read};
use test::Bencher;
#[bench]
fn bench_init_vm(bencher: &mut Bencher) {
let mut file = File::open("tests/elfs/pass_stack_reference.so").unwrap();
let mut elf = Vec::new();
file.read_to_end(&mut elf).unwrap();
let executable = Executable::<UserError, TestInstructionMeter>::from_elf(
&elf,
None,
Config::default(),
SyscallRegistry::default(),
)
.unwrap();
bencher.iter(|| {
EbpfVm::<UserError, TestInstructionMeter>::new(&executable, &mut [], Vec::new()).unwrap()
});
}
#[cfg(not(windows))]
#[bench]
fn bench_jit_compile(bencher: &mut Bencher) {
let mut file = File::open("tests/elfs/pass_stack_reference.so").unwrap();
let mut elf = Vec::new();
file.read_to_end(&mut elf).unwrap();
let mut executable = Executable::<UserError, TestInstructionMeter>::from_elf(
&elf,
None,
Config::default(),
SyscallRegistry::default(),
)
.unwrap();
bencher.iter(|| {
Executable::<UserError, TestInstructionMeter>::jit_compile(&mut executable).unwrap()
});
}