Skip to Main Content
Intel Threading Building Blocks
book

Intel Threading Building Blocks

by James Reinders
July 2007
Intermediate to advanced content levelIntermediate to advanced
332 pages
10h 4m
English
O'Reilly Media, Inc.
Content preview from Intel Threading Building Blocks

Chapter 8. Timing

Intel Threading Building Blocks provides a thread-safe and portable method to compute elapsed time.

Many operating systems provide a fine-grained method to track the accounting of central processing unit (CPU) time, and most provide a way to track elapsed/wall-clock time. The method of extracting an elapsed measurement with subsecond accuracy varies a great deal.

The class tick_count in Threading Building Blocks provides a simple interface for measuring wall-clock time, as shown in Example 8-1.

Example 8-1. Using tick_count to measure elapsed time

#include "tbb/tick_count.h"
using namespace tbb;
...
tick_count t0 = tick_count::now();
... do some work ...
tick_count t1 = tick_count::now();
printf("work took %g seconds\n",(t1-t0).seconds());

This is guaranteed to work even if the processor core running a task changes while the work is being done, and therefore the tick_count calls run on different processors.

Tip

Unlike some timing interfaces, tick_count is guaranteed to be safe to use across threads. It is based on a common or global clock. It is valid to subtract tick_count values that were created by different threads to compute elapsed time.

A tick_count value obtained from the static method tick_count::now() represents the current absolute time. This value has no meaning other than for use in comparisons with other tick_count values. Subtracting two tick_count values yields a relative time in tick_count::interval_t, as shown in Example 8-1. Relative time is expressed ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Intel® Xeon Phi™ Coprocessor Architecture and Tools: The Guide for Application Developers

Intel® Xeon Phi™ Coprocessor Architecture and Tools: The Guide for Application Developers

Rezaur Rahman

Publisher Resources

ISBN: 9780596514808Errata Page