eka toimiva

This commit is contained in:
2026-04-01 22:14:48 +03:00
parent d70fd81f05
commit 02f6684378
8 changed files with 235 additions and 24 deletions

View File

@@ -117,10 +117,11 @@ async fn run_pair_comparison(en_text: String, fi_text: String, ws: Rc<RefCell<We
return;
};
let start_time = js_sys::Date::now();
let perf = web_sys::window().unwrap().performance().unwrap();
let start_time = perf.now();
let en_result = tokenize_text(&tokenizer, &en_text);
let fi_result = tokenize_text(&tokenizer, &fi_text);
let duration = (js_sys::Date::now() - start_time) as u64;
let duration_ms = perf.now() - start_time; // millisekunteja desimaalitarkkuudella
let en_cpt = en_result["chars_per_token"].as_f64().unwrap_or(0.0);
let fi_cpt = fi_result["chars_per_token"].as_f64().unwrap_or(0.0);
@@ -132,15 +133,15 @@ async fn run_pair_comparison(en_text: String, fi_text: String, ws: Rc<RefCell<We
((fi_tokens as f64 / en_tokens as f64) - 1.0) * 100.0
} else { 0.0 };
console_log!("EN: {} tokenia ({:.2} m/t) vs FI: {} tokenia ({:.2} m/t) | ylikustannus: {:.0}%",
en_tokens, en_cpt, fi_tokens, fi_cpt, overhead_pct);
console_log!("EN: {} tokenia ({:.2} m/t) vs FI: {} tokenia ({:.2} m/t) | ylikustannus: {:.0}% | {:.2}ms",
en_tokens, en_cpt, fi_tokens, fi_cpt, overhead_pct, duration_ms);
let pair_done = serde_json::json!({
"type": "pair_done",
"en": en_result,
"fi": fi_result,
"overhead_pct": (overhead_pct * 10.0).round() / 10.0,
"duration_ms": duration,
"duration_ms": (duration_ms * 100.0).round() / 100.0,
"tokenizer": "Qwen2.5-Coder-0.5B",
});
let _ = ws.borrow().send_with_str(&pair_done.to_string());