llama_cpp_bindings/ggml_time_us.rs
1/// Get the time in microseconds according to ggml.
2///
3/// ```
4/// # use std::time::Duration;
5/// # use llama_cpp_bindings::llama_backend::LlamaBackend;
6/// let backend = LlamaBackend::init().unwrap();
7/// use llama_cpp_bindings::ggml_time_us;
8///
9/// let start = ggml_time_us();
10///
11/// std::thread::sleep(Duration::from_micros(10));
12///
13/// let end = ggml_time_us();
14///
15/// let elapsed = end - start;
16///
17/// assert!(elapsed >= 10)
18#[must_use]
19pub fn ggml_time_us() -> i64 {
20 unsafe { llama_cpp_bindings_sys::ggml_time_us() }
21}
22
23#[cfg(test)]
24mod tests {
25 use super::ggml_time_us;
26
27 #[test]
28 fn returns_positive_value() {
29 let time_microseconds = ggml_time_us();
30
31 assert!(time_microseconds > 0);
32 }
33}