increase speed giga

This commit is contained in:
Rolf Martin Glomsrud 2022-11-08 02:30:46 +01:00
parent 4a8a7de62c
commit 906dacf28b
3 changed files with 17 additions and 4 deletions

View file

@ -30,8 +30,10 @@ impl Algorithm{
yield list.swap(j, j-1); yield list.swap(j, j-1);
j = j-1; j = j-1;
} }
} }
} }
} }
pub fn stalinSort(length:i32) -> impl Generator<Yield=GuiVec, Return=()>{ pub fn stalinSort(length:i32) -> impl Generator<Yield=GuiVec, Return=()>{

View file

@ -1,5 +1,6 @@
use std::ops::{Generator, GeneratorState}; use std::ops::{Generator, GeneratorState};
use std::pin::Pin; use std::pin::Pin;
use std::time::Instant;
use macroquad::color::{BLACK, WHITE}; use macroquad::color::{BLACK, WHITE};
use macroquad::math::Vec2; use macroquad::math::Vec2;
use macroquad::prelude::{clear_background, draw_text, get_fps, get_time, next_frame, screen_width}; use macroquad::prelude::{clear_background, draw_text, get_fps, get_time, next_frame, screen_width};
@ -18,12 +19,18 @@ impl State{
let mut ret = false; let mut ret = false;
let mut lasttime:f64 = 0.; let mut lasttime:f64 = 0.;
let mut holder = GuiVec::new(screen_width(), screen_height(), length); let mut holder = GuiVec::new(screen_width(), screen_height(), length);
let mut counter = 0;
loop{ loop{
clear_background(WHITE); clear_background(WHITE);
if get_time()-lasttime > timeout && !finished && !paused{ if get_time()-lasttime > timeout && !finished && !paused{
let now = Instant::now();
match Pin::new(& mut generator).resume(()){ match Pin::new(& mut generator).resume(()){
GeneratorState::Yielded(x) => { GeneratorState::Yielded(x) => {
holder = x; holder = x;
let elapsed = now.elapsed();
//println!("{}", elapsed.as_micros());
println!("{}", get_fps())
}, },
GeneratorState::Complete(x) => { GeneratorState::Complete(x) => {
finished = true; finished = true;
@ -51,8 +58,12 @@ impl State{
if (finished && ret) || ret { if (finished && ret) || ret {
break; break;
} }
if counter != 20{
next_frame().await counter += 1;
}else{
counter = 0;
next_frame().await
}
} }
} }
} }

View file

@ -19,9 +19,9 @@ use crate::Algorithm::AlgoEnum;
#[macroquad::main("BeepSort")] #[macroquad::main("BeepSort")]
async fn main() { async fn main() {
let mut length = 100; let mut length = 200;
let mut delay = 0.01; let mut delay = 0.0;
loop{ loop{
clear_background(WHITE); clear_background(WHITE);