# Profiling with a decorator and @njit

**URL:** <https://numba.discourse.group/t/profiling-with-a-decorator-and-njit/55>\
**Category:** Community Support\
**Created:** [June 18, 2020, 9:14am UTC](https://numba.discourse.group/t/profiling-with-a-decorator-and-njit/55 "2020-06-18T09:14:20Z")\
**Posts on this page:** 1\
**Showing post:** 21

<div class="post-metadata">

**Author:** ![stuartarchibald](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/stuartarchibald/32/10_2.png) [@stuartarchibald](https://numba.discourse.group/u/stuartarchibald)\
**Post date:** [July 7, 2020, 11:13am UTC](https://numba.discourse.group/t/profiling-with-a-decorator-and-njit/55/21 "2020-07-07T11:13:34Z")

</div>

Non-portably, for linux:

```auto
from numba import njit, objmode
import numpy as np
import ctypes
import time

CLOCK_MONOTONIC = 0x1
clock_gettime_proto = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_int,
                                       ctypes.POINTER(ctypes.c_long))
pybind = ctypes.CDLL(None)
clock_gettime_addr = pybind.clock_gettime
clock_gettime_fn_ptr = clock_gettime_proto(clock_gettime_addr)

@njit
def timenow():
    timespec = np.zeros(2, dtype=np.int64)
    clock_gettime_fn_ptr(CLOCK_MONOTONIC, timespec.ctypes)
    ts = timespec[0]
    tns = timespec[1]
    return np.float64(ts) + 1e-9 * np.float64(tns)

@njit
def pointless_delay(seconds):
    with objmode():
        s = time.time()
        e = 0
        while (e < seconds):
            e = time.time() - s

@njit
def do_stuff(n):
    t0 = timenow()
    pointless_delay(n)
    print("Elapsed", timenow() - t0)

do_stuff(1)
do_stuff(2)
do_stuff(3.21)

```

to do this portably it’ll need support adding in Numba, probably in the form of a translation of the CPython internals for the `time` module.

---

_[View the full topic](https://numba.discourse.group/t/profiling-with-a-decorator-and-njit/55)._
