Standard Library
Time (time)

Time Module (time)

Module Implementation: Provides time measurement and benchmarking utilities for performance monitoring.

Functions

time.now_ms()

Get current timestamp in milliseconds.

Returns:

  • number: The current timestamp in milliseconds.

Example:

// Get current timestamp in milliseconds
let start_ms = time.now_ms();
print("Benchmark started at:", start_ms, "ms");
 
// Perform some work
sleep(250);
 
// Calculate elapsed time in seconds since start
let elapsed_s = time.since_s(start_ms);
print("Elapsed time:", elapsed_s, "seconds");
 
let end_ms = time.now_ms();
print("Total duration:", end_ms - start_ms, "ms");

time.since_s(reference_ms)

Calculate elapsed time in seconds since the reference timestamp.

Arguments:

  • reference_ms (number): The reference timestamp in milliseconds (usually obtained from time.now_ms()).

Returns:

  • number: The elapsed time in seconds.

Example:

let start_ms = time.now_ms();
// ... do some work ...
let elapsed_s = time.since_s(start_ms);
print("Elapsed time:", elapsed_s, "seconds");

Time Functions:

  • time.now_ms() - Returns current timestamp in milliseconds
  • time.since_s(reference_ms) - Returns elapsed time in seconds since the reference timestamp

Performance Benchmarking

Use the time module to measure execution performance:

let start_ms = time.now_ms();
 
// Perform intensive operation
let sum = 0;
let i = 0;
while (i < 100000000) {
    sum = sum + i;
    i = i + 1;
}
 
let elapsed_s = time.since_s(start_ms);
print("Sum:", sum);
print("Time:", elapsed_s, "seconds");

Next Steps