Update Wasmer, log load times, some minor performance tweaks
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use chrono::Duration;
|
||||
use std::convert::TryFrom;
|
||||
use std::fmt::Debug;
|
||||
use std::fs::File;
|
||||
@@ -24,18 +25,45 @@ use pkmn_lib::static_data::{
|
||||
};
|
||||
use pkmn_lib::StringKey;
|
||||
|
||||
pub fn load_library() -> Arc<dyn DynamicLibrary> {
|
||||
pub struct LoadResult {
|
||||
pub library: Arc<dyn DynamicLibrary>,
|
||||
pub types_load_time: Duration,
|
||||
pub natures_load_time: Duration,
|
||||
pub items_load_time: Duration,
|
||||
pub growth_rate_load_time: Duration,
|
||||
pub abilities_load_time: Duration,
|
||||
pub moves_load_time: Duration,
|
||||
pub species_load_time: Duration,
|
||||
pub wasm_load_time: Duration,
|
||||
}
|
||||
|
||||
pub fn load_library() -> LoadResult {
|
||||
let mut path = get_project_root().unwrap();
|
||||
path.push("tests/data/");
|
||||
let path = path.to_str().unwrap().to_string();
|
||||
|
||||
let t1 = chrono::Utc::now();
|
||||
let types = load_types(&path);
|
||||
let t2 = chrono::Utc::now();
|
||||
let types_load_time = t2 - t1;
|
||||
let natures = load_natures(&path);
|
||||
let t1 = chrono::Utc::now();
|
||||
let natures_load_time = t1 - t2;
|
||||
let items = load_items(&path);
|
||||
let t2 = chrono::Utc::now();
|
||||
let items_load_time = t2 - t1;
|
||||
let growth_rates = load_growth_rates(&path);
|
||||
let t1 = chrono::Utc::now();
|
||||
let growth_rate_load_time = t1 - t2;
|
||||
let abilities = load_abilities(&path);
|
||||
let t2 = chrono::Utc::now();
|
||||
let abilities_load_time = t2 - t1;
|
||||
let moves = load_moves(&path, &types);
|
||||
let t1 = chrono::Utc::now();
|
||||
let moves_load_time = t1 - t2;
|
||||
let species = load_species(&path, &types, &moves);
|
||||
let t2 = chrono::Utc::now();
|
||||
let species_load_time = t2 - t1;
|
||||
|
||||
let data = StaticDataImpl::new(
|
||||
Box::new(LibrarySettingsImpl::new(100)),
|
||||
@@ -47,16 +75,32 @@ pub fn load_library() -> Arc<dyn DynamicLibrary> {
|
||||
natures,
|
||||
abilities,
|
||||
);
|
||||
|
||||
let t1 = chrono::Utc::now();
|
||||
let mut resolver = WebAssemblyScriptResolver::new();
|
||||
load_wasm(&path, resolver.as_mut());
|
||||
let t2 = chrono::Utc::now();
|
||||
let wasm_load_time = t2 - t1;
|
||||
|
||||
Arc::new(DynamicLibraryImpl::new(
|
||||
let library = Arc::new(DynamicLibraryImpl::new(
|
||||
Box::new(data),
|
||||
Box::new(Gen7BattleStatCalculator::new()),
|
||||
Box::new(Gen7DamageLibrary::new(false)),
|
||||
Box::new(Gen7MiscLibrary::new()),
|
||||
resolver,
|
||||
))
|
||||
));
|
||||
|
||||
LoadResult {
|
||||
library,
|
||||
types_load_time,
|
||||
natures_load_time,
|
||||
items_load_time,
|
||||
growth_rate_load_time,
|
||||
abilities_load_time,
|
||||
moves_load_time,
|
||||
species_load_time,
|
||||
wasm_load_time,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load_types(path: &String) -> Box<dyn TypeLibrary> {
|
||||
|
||||
@@ -19,16 +19,35 @@ use crate::common::{library_loader, TestCase};
|
||||
pub mod common;
|
||||
|
||||
fn get_library() -> Arc<dyn DynamicLibrary> {
|
||||
library_loader::load_library()
|
||||
library_loader::load_library().library
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg_attr(miri, ignore)]
|
||||
fn validate_library_load() {
|
||||
let start_time = chrono::Utc::now();
|
||||
library_loader::load_library();
|
||||
let result = library_loader::load_library();
|
||||
let end_time = chrono::Utc::now();
|
||||
println!("Built library in {} ms", (end_time - start_time).num_milliseconds());
|
||||
println!(
|
||||
"Built library in {} ms\
|
||||
\n\t- Types load time: {} ms\
|
||||
\n\t- Natures load time: {} ms\
|
||||
\n\t- Items load time: {} ms\
|
||||
\n\t- Growth Rate load time: {} ms\
|
||||
\n\t- Abilities load time: {} ms\
|
||||
\n\t- Moves load time: {} ms\
|
||||
\n\t- Species load time: {} ms\
|
||||
\n\t- WASM load time: {} ms\
|
||||
",
|
||||
(end_time - start_time).num_milliseconds(),
|
||||
result.types_load_time.num_milliseconds(),
|
||||
result.natures_load_time.num_milliseconds(),
|
||||
result.items_load_time.num_milliseconds(),
|
||||
result.growth_rate_load_time.num_milliseconds(),
|
||||
result.abilities_load_time.num_milliseconds(),
|
||||
result.moves_load_time.num_milliseconds(),
|
||||
result.species_load_time.num_milliseconds(),
|
||||
result.wasm_load_time.num_milliseconds(),
|
||||
);
|
||||
}
|
||||
|
||||
#[datatest::files("tests/test_cases", {
|
||||
|
||||
Reference in New Issue
Block a user