forked from solana-labs/rbpf
-
Notifications
You must be signed in to change notification settings - Fork 1
/
jit_compile.rs
53 lines (48 loc) · 1.77 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_sbpf;
extern crate test;
use solana_sbpf::{
elf::Executable, program::BuiltinProgram, verifier::RequisiteVerifier, vm::TestContextObject,
};
use std::{fs::File, io::Read, sync::Arc};
use test::Bencher;
use test_utils::create_vm;
#[bench]
fn bench_init_vm(bencher: &mut Bencher) {
let mut file = File::open("tests/elfs/relative_call_sbpfv0.so").unwrap();
let mut elf = Vec::new();
file.read_to_end(&mut elf).unwrap();
let executable =
Executable::<TestContextObject>::from_elf(&elf, Arc::new(BuiltinProgram::new_mock()))
.unwrap();
executable.verify::<RequisiteVerifier>().unwrap();
bencher.iter(|| {
let mut context_object = TestContextObject::default();
create_vm!(
_vm,
&executable,
&mut context_object,
stack,
heap,
Vec::new(),
None
);
});
}
#[cfg(all(feature = "jit", not(target_os = "windows"), target_arch = "x86_64"))]
#[bench]
fn bench_jit_compile(bencher: &mut Bencher) {
let mut file = File::open("tests/elfs/relative_call_sbpfv0.so").unwrap();
let mut elf = Vec::new();
file.read_to_end(&mut elf).unwrap();
let mut executable =
Executable::<TestContextObject>::from_elf(&elf, Arc::new(BuiltinProgram::new_mock()))
.unwrap();
executable.verify::<RequisiteVerifier>().unwrap();
bencher.iter(|| executable.jit_compile().unwrap());
}