// Copyright 2022 Cartallum CBE Maintainers // // Licensed under the Apache License, Version 2.0 or // the MIT license , at your option. This file may not be // copied, modified, or distributed except according to those terms. #![feature(test)] extern crate cbe_rbpf; extern crate test; use cbe_rbpf::{ elf::Executable, vm::{BuiltInProgram, Config, EbpfVm, TestContextObject, VerifiedExecutable}, }; use std::{fs::File, io::Read, sync::Arc}; use test::Bencher; use test_utils::TautologyVerifier; #[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::::from_elf( &elf, Arc::new(BuiltInProgram::new_loader(Config::default())), ) .unwrap(); let verified_executable = VerifiedExecutable::::from_executable(executable) .unwrap(); bencher.iter(|| { let mut context_object = TestContextObject::default(); EbpfVm::new( &verified_executable, &mut context_object, &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 executable = Executable::::from_elf( &elf, Arc::new(BuiltInProgram::new_loader(Config::default())), ) .unwrap(); let mut verified_executable = VerifiedExecutable::::from_executable(executable) .unwrap(); bencher.iter(|| verified_executable.jit_compile().unwrap()); }