Skip to content

Instantly share code, notes, and snippets.

@greyblake
Created April 22, 2021 16:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greyblake/3cc0b88e4fa314e69157bb910b56212f to your computer and use it in GitHub Desktop.
Save greyblake/3cc0b88e4fa314e69157bb910b56212f to your computer and use it in GitHub Desktop.
Whatlang VS Lingua Performance
use lingua::LanguageDetectorBuilder;
use std::time::Instant;
const N: usize = 10_000;
fn main() {
let goethe = "Wir sollen eben nicht in Ruhe bleiben! Gleich wird uns, wenn wir zu genießen denken, Zur Übung unsrer Tapferkeit ein Feind, Zur Übung der Geduld ein Freund gegeben";
let pushkin = "Я помню чудное мгновенье: Передо мной явилась ты, Как мимолетное виденье, Как гений чистой красоты.";
let detector = LanguageDetectorBuilder::from_all_languages().build();
detector.detect_language_of(goethe);
detector.detect_language_of(pushkin);
{
let start = Instant::now();
for _ in 0..N {
detector.detect_language_of(goethe);
detector.detect_language_of(pushkin);
}
let duration = Instant::now() - start;
println!("Lingua: {:?}", duration);
}
{
let start = Instant::now();
for _ in 0..N {
whatlang::detect(goethe);
whatlang::detect(pushkin);
}
let duration = Instant::now() - start;
println!("Whatlang: {:?}", duration);
}
}
// OUTPUT
// Lingua: 19.271317911s
// Whatlang: 1.702979395s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment