@@ -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.
2635fn 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