background preloader

Gnu

Facebook Twitter

C/C++ tip: How to measure elapsed real time for benchmarking. API functions to get the real time (wall-clock time) at sub-second resolution differ between Windows, Linux, OSX, BSD, Solaris, and other UNIX-style OSes. This article provides a cross-platform function to get the real time, and explains what works on what OS. How to get the elapsed real time For benchmarking, we're interested in the elapsed real world time between the start and end of some code of interest. For this purpose, we need time values with sub-second accuracy and we don't care about time zones and date formats. This eliminates most of the API calls available in today's OSes because they only return times in seconds and produce nicely formatted strings for display to a human. What we need is a low-level notion of time that reliably ticks over every few nanoseconds. Code The following getRealTime( ) function works for most OSes (copy and paste, or download getRealTime.c).

See the sections that follow for discussion, caveats, and why this code requires so many #ifdef's. Usage time( ) Autoconf, Automake, and Libtool: Introduction. Autoconf, Automake and Libtool are packages for making your software more portable and to simplify building it--usually on someone else's system. Software portability and effective build systems are crucial aspects of modern software engineering practice. It is unlikely that a software project would be started today with the expectation that the software would run on only one platform. Hardware constraints may change the choice of platform, new customers with different kinds of systems may emerge or your vendor might introduce incompatible changes in newer versions of their operating system.

In addition, tools that make building software easier and less error prone are valuable. Autoconf is a tool that makes your packages more portable by performing tests to discover system characteristics before the package is compiled. Automake is a tool for generating `Makefile's--descriptions of what to build--that conform to a number of standards. GNU build system. GNU logo It can be difficult to make a software program portable: the C compiler differs from system to system; certain library functions are missing on some systems; header files may have different names. One way to handle this is to write conditional code, with code blocks selected by means of preprocessor directives (#ifdef); but because of the wide variety of build environments this approach quickly becomes unmanageable.

Autotools is designed to address this problem more manageably. Autotools is part of the GNU toolchain and is widely used in many free software and open source packages. The GNU build system makes it possible to build many programs using a two step process: configure followed by make.[3] Components[edit] Flow diagram of autoconf and automake GNU Autoconf[edit] Autoconf generates a configure script based on the contents of a configure.ac file which characterizes a particular body of source code. GNU Automake[edit] GNU Libtool[edit] Gnulib[edit] Usage[edit] See also[edit] The Julia Language.