Skip to main content
Skip table of contents

GetHostTick [LJM User's Guide]

Queries the host system's steady (monotonic) clock, preferentially with high precision.

Syntax

LJM_LONG_LONG_RETURN LJM_GetHostTick()

Returns

The current clock tick in microseconds, as a 64-bit integer. Resolution may vary.

On Windows, sleep states (such as standby, hibernate, or connected standby) do not affect LJM_GetHostTick. Other platforms should be manually tested.

Compatibility

Some development environments can not handle the 64-bit return value. In such cases use LJM_GetHostTick32Bit which uses two 32-bit parameters to return the clock tick.

Example

Measure how long an operation takes.

C
double value;
long long time0 = LJM_GetHostTick();
err = LJM_eReadName(handle, "SERIAL_NUMBER", &value);
long long time1 = LJM_GetHostTick();
ErrorCheck(err, "LJM_eReadName");
printf("LJM_eReadName took %lld microseconds.\n", time1 - time0);

Device I/O times can vary greatly, but this prints something like:

LJM_eReadName took 338 microseconds.

Determining What's Slow

There are a number of spots in your code that could be incurring a delay. These include:

  • Communication with a LabJack device

  • Communication with other devices

  • Other I/O

  • Graphics

  • CPU-intensive tasks

If your loop is too slow, try timing which part of the loop is slow. A good way to do this is to measure two sections: how long a section of code takes and how long the entire loop takes. Then, output both times and compare.

With pseudo-C code this could look like the following:

long long tloop = 0;
for (...) {
long long t0 = LJM_GetHostTick();
// The section under test goes here
long long t1 = LJM_GetHostTick();

if (tloop != 0) {
printf("The code section took %lld microseconds;", t1 - t0);
printf(" the whole loop took %lld microseconds\n", t1 - tloop);
}
tloop = t1;
}

After the first loop, this uses the second GetHostTick and a temporary variable to measure total loop time.

Each line shows how long the code section took compared to the whole loop:

The code section took 370 microseconds; the whole loop took 378 microseconds
The code section took 325 microseconds; the whole loop took 333 microseconds
...

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.