aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / crates / allen-reflex / examples / bench.rs
| 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | |
| 16 | //! Speed and size. usage: taskset -c 0 cargo run --release -p allen-reflex --example bench |
| 17 | //! Times the whole path a message takes (tokenize, segment, policy, features, encode, score, |
| 18 | //! span copy, JSON) on the train and dev messages, single thread. Never reads held-out. |
| 19 | #[path = "common/mod.rs"] |
| 20 | mod common; |
| 21 | use allen_reflex::{exam_turns, Config, Mode}; |
| 22 | use common::*; |
| 23 | use std::time::Instant; |
| 24 | |
| 25 | fn main() { |
| 26 | let pool = pool(); |
| 27 | let mut msgs = load("train"); |
| 28 | msgs.extend(load("dev")); |
| 29 | let reps = 50; |
| 30 | println!("messages {} x {reps} repetitions, one thread", msgs.len()); |
| 31 | println!("mode build_ms memory_bytes median_us p99_us max_us decisions_per_s"); |
| 32 | for mode in [Mode::Reflex, Mode::Nearest, Mode::Perceptron] { |
| 33 | let refs: Vec<&Case> = pool.iter().collect(); |
| 34 | let t0 = Instant::now(); |
| 35 | let mut core = build(Config::frozen(mode), &refs); |
| 36 | let build_ms = t0.elapsed().as_secs_f64() * 1e3; |
| 37 | core.set_learning(false); |
| 38 | let turns: Vec<_> = msgs.iter().map(|c| exam_turns(&c.turns)).collect(); |
| 39 | // warm up |
| 40 | for t in &turns { |
| 41 | std::hint::black_box(core.decide(t)); |
| 42 | } |
| 43 | let mut lat = Vec::with_capacity(turns.len() * reps); |
| 44 | let all = Instant::now(); |
| 45 | for _ in 0..reps { |
| 46 | for t in &turns { |
| 47 | let s = Instant::now(); |
| 48 | let d = core.decide(t); |
| 49 | let j = d.0.json(); |
| 50 | std::hint::black_box((d, j)); |
| 51 | lat.push(s.elapsed().as_nanos() as u64); |
| 52 | } |
| 53 | } |
| 54 | let secs = all.elapsed().as_secs_f64(); |
| 55 | lat.sort_unstable(); |
| 56 | let p = |q: f64| lat[((lat.len() as f64 - 1.0) * q) as usize] as f64 / 1e3; |
| 57 | println!( |
| 58 | "{:<10} {:>8.1} {:>12} {:>9.1} {:>6.1} {:>6.1} {:>15.0}", |
| 59 | mode.name(), |
| 60 | build_ms, |
| 61 | core.memory_bytes(), |
| 62 | p(0.5), |
| 63 | p(0.99), |
| 64 | p(1.0), |
| 65 | lat.len() as f64 / secs |
| 66 | ); |
| 67 | } |
| 68 | } |