Measuring time accurately on Linux

(Michal Kalinowski) #1

It's my first time posting to users mailing list so hello everyone.

I'm currently optimizing code of my server written in Swift. To do that reliably I want to be able to measure how long it takes to execute specific methods.

On OSX I'm using mach_absolute_time() that I've wrapped in a struct for easier interaction and it works fine. Now I'd like to do the same tests on a copy of my actual platform that runs Ubuntu 15.10.

Mach0 library that I use is not available on Linux, instead I could use gettimeofday or clock_gettime. For that I would have to expose time.h to my swift code, however I'm unsure how to do it exactly.
I have started putting my timing struct in a swift package as a first step. Now I'm stuck and here are my questions:
* How exactly do I use clang's modulemap with package manager?
* How do I make modulemap include time.h only on Linux?
* Is it necessary to include full path to time.h header or I can omit it in case of system headers?

Here is a link to my package for future reference (no linux code there for now).

Also, if anyone is aware of a package that uses C library in place of OSX C method to work cross-platform please let me know. It would be a great guidance for me as I have a very vague idea of how package manager and C libs import work.

M. Kalinowski