Working with Time using “time” Package in Mojo Programming Language

Shriram Sivanandhan
2 min readMar 29, 2024

--

Mojo Programming Language combines the usability of Python with the performance of C, C++ and Rust. Mojo Programming Language utilizes next-generation compiler technologies with features like caching, multithreading and cloud distribution technologies. Further, Auto-Tuning and compile-time Metaprogramming features allows to write code for several hardware. The advantages of Mojo Programming Language are Usability & Programmability, best performance, Interoperability and Extensibility.

As we saw Interoperability of Mojo Programming Language with Python Ecosystem to use Matplotlib Python Visualization Library, Pandas Python Data Analysis and Manipulation Library, NumPy (Fundamental Package for Scientific Computing in Python) Library and SciPy Python Library in Mojo Programming Language in previous Articles/Blogs. In this Article/Blog, we are going to see on Working with Time using time Package in Mojo Programming Language, where we are going to use now() function by importing it from time package which returns the current monotonic time in nanoseconds where this function queries the current platform’s monotonic clock.

Since the older JupyterLab-based Mojo Playground is deprecated, in this Blog, Programming in Mojo is done using the new Mojo Playground.

Working with Time using “time” Package in Mojo Programming Language:

We are going to use APIs from time Package in Mojo Programming Language. In Mojo Programming Language, time package implements the basic utils for working with time.

Here in the Example below we are going to use now() function by importing it from time package which returns the current monotonic time in nanoseconds where this function queries the current platform’s monotonic clock,

Using now() function by importing it from time package which returns the current monotonic time in nanoseconds where this function queries the current platform’s monotonic clock in Mojo Programming Language
Using now() function by importing it from time package which returns the current monotonic time in nanoseconds where this function queries the current platform’s monotonic clock in Mojo Programming Language (New Mojo Playground)

We had seen about Working with Time using time Package in Mojo Programming Language, where we saw using now() function by importing it from time package which returns the current monotonic time in nanoseconds where this function queries the current platform’s monotonic clock. Programming in Mojo and Mojo Programming concepts will be discussed further.

Thankyou for reading this blog on Working with Time using “time” Package in Mojo Programming Language.

Reference:

https://docs.modular.com/mojo/manual/

https://docs.modular.com/mojo/manual/basics/

https://docs.modular.com/mojo/stdlib/time/time

--

--

No responses yet