Add basic benchmarks and CI
This commit is contained in:
22
.github/workflows/benchmark.yaml
vendored
Normal file
22
.github/workflows/benchmark.yaml
vendored
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
name: Benchmark
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
benchmark:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
lfs: 'true'
|
||||||
|
submodules: 'recursive'
|
||||||
|
- name: Install latest nightly
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: nightly
|
||||||
|
override: true
|
||||||
|
- name: Install Protoc
|
||||||
|
uses: arduino/setup-protoc@v3
|
||||||
|
- name: Run Tests
|
||||||
|
run: cargo bench
|
||||||
42
.github/workflows/test.yaml
vendored
Normal file
42
.github/workflows/test.yaml
vendored
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
name: Testing/Linting
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
lfs: 'true'
|
||||||
|
submodules: 'recursive'
|
||||||
|
- name: Install latest nightly
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: nightly
|
||||||
|
override: true
|
||||||
|
- name: Install Protoc
|
||||||
|
uses: arduino/setup-protoc@v3
|
||||||
|
- name: Run Tests
|
||||||
|
run: cargo test
|
||||||
|
|
||||||
|
lint:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
crate: [analysis, backend]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Install latest nightly
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: nightly
|
||||||
|
override: true
|
||||||
|
components: rustfmt, clippy
|
||||||
|
- name: Install Protoc
|
||||||
|
uses: arduino/setup-protoc@v3
|
||||||
|
- name: Run Clippy
|
||||||
|
run: cargo clippy
|
||||||
|
- name: Run formatting
|
||||||
|
run: cargo fmt --check
|
||||||
82
Cargo.lock
generated
82
Cargo.lock
generated
@@ -1,6 +1,6 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
# This file is automatically @generated by Cargo.
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 4
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "aho-corasick"
|
name = "aho-corasick"
|
||||||
@@ -11,6 +11,12 @@ dependencies = [
|
|||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle"
|
||||||
|
version = "1.0.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anyhow"
|
name = "anyhow"
|
||||||
version = "1.0.88"
|
version = "1.0.88"
|
||||||
@@ -41,11 +47,44 @@ version = "1.0.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap"
|
||||||
|
version = "4.5.20"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b97f376d85a664d5837dbae44bf546e6477a679ff6610010f17276f686d867e8"
|
||||||
|
dependencies = [
|
||||||
|
"clap_builder",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap_builder"
|
||||||
|
version = "4.5.20"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "19bc80abd44e4bed93ca373a0704ccbd1b710dc5749406201bb018272808dc54"
|
||||||
|
dependencies = [
|
||||||
|
"anstyle",
|
||||||
|
"clap_lex",
|
||||||
|
"terminal_size",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap_lex"
|
||||||
|
version = "0.7.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "condtype"
|
||||||
|
version = "1.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "baf0a07a401f374238ab8e2f11a104d2851bf9ce711ec69804834de8af45c7af"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "csdemo"
|
name = "csdemo"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitter",
|
"bitter",
|
||||||
|
"divan",
|
||||||
"phf",
|
"phf",
|
||||||
"pretty_assertions",
|
"pretty_assertions",
|
||||||
"prost",
|
"prost",
|
||||||
@@ -61,6 +100,31 @@ version = "0.1.13"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8"
|
checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "divan"
|
||||||
|
version = "0.1.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a0d567df2c9c2870a43f3f2bd65aaeb18dbce1c18f217c3e564b4fbaeb3ee56c"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"clap",
|
||||||
|
"condtype",
|
||||||
|
"divan-macros",
|
||||||
|
"libc",
|
||||||
|
"regex-lite",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "divan-macros"
|
||||||
|
version = "0.1.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "27540baf49be0d484d8f0130d7d8da3011c32a44d4fc873368154f1510e574a2"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "either"
|
name = "either"
|
||||||
version = "1.13.0"
|
version = "1.13.0"
|
||||||
@@ -343,6 +407,12 @@ dependencies = [
|
|||||||
"regex-syntax",
|
"regex-syntax",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-lite"
|
||||||
|
version = "0.1.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "53a49587ad06b26609c52e423de037e7f57f20d53535d66e08c695f347df952a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex-syntax"
|
name = "regex-syntax"
|
||||||
version = "0.8.4"
|
version = "0.8.4"
|
||||||
@@ -398,6 +468,16 @@ dependencies = [
|
|||||||
"windows-sys 0.59.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "terminal_size"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4f599bd7ca042cfdf8f4512b277c02ba102247820f9d9d4a9f521f496751a6ef"
|
||||||
|
dependencies = [
|
||||||
|
"rustix",
|
||||||
|
"windows-sys 0.59.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-ident"
|
name = "unicode-ident"
|
||||||
version = "1.0.13"
|
version = "1.0.13"
|
||||||
|
|||||||
@@ -18,6 +18,11 @@ regex = "1.10.6"
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
pretty_assertions = { version = "1.4" }
|
pretty_assertions = { version = "1.4" }
|
||||||
|
divan = "0.1.14"
|
||||||
|
|
||||||
|
[[bench]]
|
||||||
|
name = "example"
|
||||||
|
harness = false
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
prost-build = { version = "0.13.2" }
|
prost-build = { version = "0.13.2" }
|
||||||
|
|||||||
34
benches/example.rs
Normal file
34
benches/example.rs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#[global_allocator]
|
||||||
|
static ALLOC: divan::AllocProfiler = divan::AllocProfiler::system();
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
divan::main();
|
||||||
|
}
|
||||||
|
|
||||||
|
mod eager {
|
||||||
|
#[divan::bench(max_time = std::time::Duration::from_secs(30))]
|
||||||
|
fn no_entities_mirage() -> csdemo::parser::FirstPassOutput {
|
||||||
|
let raw_bytes = include_bytes!("../testfiles/mirage.dem");
|
||||||
|
|
||||||
|
let container = csdemo::Container::parse(divan::black_box(raw_bytes.as_slice())).unwrap();
|
||||||
|
|
||||||
|
csdemo::parser::parse(
|
||||||
|
csdemo::FrameIterator::parse(container.inner),
|
||||||
|
csdemo::parser::EntityFilter::disabled(),
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[divan::bench(max_time = std::time::Duration::from_secs(30))]
|
||||||
|
fn entities_mirage() -> csdemo::parser::FirstPassOutput {
|
||||||
|
let raw_bytes = include_bytes!("../testfiles/mirage.dem");
|
||||||
|
|
||||||
|
let container = csdemo::Container::parse(divan::black_box(raw_bytes.as_slice())).unwrap();
|
||||||
|
|
||||||
|
csdemo::parser::parse(
|
||||||
|
csdemo::FrameIterator::parse(container.inner),
|
||||||
|
csdemo::parser::EntityFilter::all(),
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -135,10 +135,13 @@ impl PropController {
|
|||||||
prop_name: "my_weapons_offset".into(),
|
prop_name: "my_weapons_offset".into(),
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
(ITEM_PURCHASE_COST, PropInfo {
|
(
|
||||||
|
ITEM_PURCHASE_COST,
|
||||||
|
PropInfo {
|
||||||
id: ITEM_PURCHASE_COST,
|
id: ITEM_PURCHASE_COST,
|
||||||
prop_name: "item_purchase_cost".into(),
|
prop_name: "item_purchase_cost".into(),
|
||||||
}),
|
},
|
||||||
|
),
|
||||||
]
|
]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.collect(),
|
.collect(),
|
||||||
|
|||||||
@@ -37,16 +37,19 @@ pub mod ccsteam {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn team_name(&self) -> Option<&str> {
|
pub fn team_name(&self) -> Option<&str> {
|
||||||
self.0.get_prop("CCSTeam.m_szTeamname").map(|p| {
|
self.0
|
||||||
match &p.value {
|
.get_prop("CCSTeam.m_szTeamname")
|
||||||
|
.map(|p| match &p.value {
|
||||||
crate::parser::Variant::String(v) => Some(v.as_str()),
|
crate::parser::Variant::String(v) => Some(v.as_str()),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
})
|
||||||
}).flatten()
|
.flatten()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn player_pawns(&self) -> Vec<super::pawnid::PawnID> {
|
pub fn player_pawns(&self) -> Vec<super::pawnid::PawnID> {
|
||||||
self.0.props.iter()
|
self.0
|
||||||
|
.props
|
||||||
|
.iter()
|
||||||
.filter(|p| p.prop_info.prop_name.as_ref() == "CCSTeam.m_aPawns")
|
.filter(|p| p.prop_info.prop_name.as_ref() == "CCSTeam.m_aPawns")
|
||||||
.filter_map(|p| p.value.as_u32())
|
.filter_map(|p| p.value.as_u32())
|
||||||
.map(|v| super::pawnid::PawnID::from(v))
|
.map(|v| super::pawnid::PawnID::from(v))
|
||||||
@@ -54,11 +57,17 @@ pub mod ccsteam {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn score(&self) -> Option<i32> {
|
pub fn score(&self) -> Option<i32> {
|
||||||
self.0.get_prop("CCSTeam.m_iScore").map(|p| p.value.as_i32()).flatten()
|
self.0
|
||||||
|
.get_prop("CCSTeam.m_iScore")
|
||||||
|
.map(|p| p.value.as_i32())
|
||||||
|
.flatten()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn team_number(&self) -> Option<u32> {
|
pub fn team_number(&self) -> Option<u32> {
|
||||||
self.0.get_prop("CCSTeam.m_iTeamNum").map(|p| p.value.as_u32()).flatten()
|
self.0
|
||||||
|
.get_prop("CCSTeam.m_iTeamNum")
|
||||||
|
.map(|p| p.value.as_u32())
|
||||||
|
.flatten()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user