Skip to content

Commit 3d5850c

Browse files
committed
Add screen_bench command.
Times how long to put 1,000,000 chars on the screen (with scrolling).
1 parent 8dad0ec commit 3d5850c

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/commands/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub static OS_MENU: menu::Menu<Ctx> = menu::Menu {
2020
#[cfg(target_os = "none")]
2121
&ram::RUN_ITEM,
2222
&screen::CLEAR_ITEM,
23+
&screen::BENCH_ITEM,
2324
&screen::FILL_ITEM,
2425
&input::KBTEST_ITEM,
2526
],

src/commands/screen.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ pub static FILL_ITEM: menu::Item<Ctx> = menu::Item {
2222
help: Some("Fill the screen with characters"),
2323
};
2424

25+
pub static BENCH_ITEM: menu::Item<Ctx> = menu::Item {
26+
item_type: menu::ItemType::Callback {
27+
function: bench,
28+
parameters: &[],
29+
},
30+
command: "screen_bench",
31+
help: Some("Time how long to put 1,000,000 characters on the screen, with scrolling."),
32+
};
33+
2534
/// Called when the "clear" command is executed.
2635
fn clear(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, _args: &[&str], _ctx: &mut Ctx) {
2736
if let Some(ref mut console) = unsafe { &mut VGA_CONSOLE } {
@@ -69,3 +78,24 @@ fn fill(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, _args: &[&str], _ctx:
6978
console.set_attr(attr);
7079
}
7180
}
81+
82+
/// Called when the "bench" command is executed.
83+
fn bench(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, _args: &[&str], _ctx: &mut Ctx) {
84+
const NUM_CHARS: u64 = 1_000_000;
85+
if let Some(ref mut console) = unsafe { &mut VGA_CONSOLE } {
86+
let api = API.get();
87+
let start = (api.time_ticks_get)();
88+
console.clear();
89+
let glyphs = &[b'x'];
90+
for _idx in 0..NUM_CHARS {
91+
console.write_bstr(glyphs);
92+
}
93+
let end = (api.time_ticks_get)();
94+
let delta = end.0 - start.0;
95+
let chars_per_second = (NUM_CHARS * (api.time_ticks_per_second)().0) / delta;
96+
println!(
97+
"{} chars in {} ticks, or {} chars per second",
98+
NUM_CHARS, delta, chars_per_second
99+
);
100+
}
101+
}

0 commit comments

Comments
 (0)