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 serial_test::serial;
26
27 use super::ggml_time_us;
28 use crate::llama_backend::LlamaBackend;
29
30 #[test]
31 #[serial]
32 fn returns_positive_value() {
33 let _backend = LlamaBackend::init().unwrap();
34 let time_microseconds = ggml_time_us();
35
36 assert!(time_microseconds > 0);
37 }
38}