The Unix time(1) command can only give a precision of 10 milliseconds by default. But being the engineer who goes insane after precision, I made my own script to be able to get differences in terms of microseconds. My first timer utility was made in C but I got stuck with the insane exec(3) family of functions since you need to fork the process to a child for the parent process to create successful timing. Hence I used Perl with the Time::HiRes library which is a wrapper to <time.h> and <sys/time.h>. Later on, I found out that C itself has the system(3) functioin in <stdlib.h>
Performance-wise you can see that C has a much faster runtime when the program was being invoked. But you can see in the graph above that Perl has much more consistent values so its standard deviation is lower than C. When I tested both programs for my data-intensive computing experiments, I get better results with the Perl utility! Perhaps I forgot to do all the magic the system function in Perl does in my C implementation?
Here is my Perl code:
#!/usr/bin/perl
use Time::HiRes qw ( tv_interval gettimeofday );
$start = [gettimeofday];
system @ARGV;
$elapsed = tv_interval ( $start );
print $elapsed, "\n";
Here is my C implementation:
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
int main(int argc, char* argv[])
{
struct timeval start, end, diff;
gettimeofday(&start, NULL);
char* command = malloc( sizeof(argv) );
int i;
sprintf(command, "%s", argv[1]);
for( i = 2; i < argc; i++ )
{
sprintf(command, "%s %s", command, argv[i]);
}
system(command);
gettimeofday(&end, NULL);
timersub(&end, &start, &diff);
printf("%d.%06d\n", diff.tv_sec, diff.tv_usec);
return 0;
}
Related Posts - Technical aspects of election computerization I was invited (via Facebook events) to attend the first CSP Kapihan discussing the technical aspects of computerizing the Philippine elections. Dr. Pablo Manalastas and Ms.Ito Gruet gave very interesting ideas and pointed out key concepts that the Comelec missed out in the planned pilot testing in the ARMM elections.......
- On iPods and being struck by lightning... I just arrived in our department from a VoIP appreciation seminar in the Advanced Science and Technology Institute (ASTI). Sir Paul, our secretary said that Dr. Toby Dayrit (the Dean) is looking for some faculty in the ECCE department to explain the relationship of the probability of being struck by......
- Technical aspects of election computerization I was invited (via Facebook events) to attend the first CSP Kapihan discussing the technical aspects of computerizing the Philippine elections. Dr. Pablo Manalastas and Ms.Ito Gruet gave very interesting ideas and pointed out key concepts that the Comelec missed out in the planned pilot testing in the ARMM elections.......
-
LEGO Brick's 50th anniversay! I was in the department this morning when something caught my attention: one of the workstations display the Google webpage. Their logo was made up of LEGO bricks! Later on, Slashdot posted the article about the 50th Anniversary of the LEGO brick. So that was the occassion. LEGO made...... -
Collated schematic diagrams When I was scouring through my files in my undergraduate years, I decided to compile all of the figures and schematic diagrams from all the lab reports and other technical papers. My preference in submitting paperwork was typesetting everything in TeX/LaTeX. It is a markup language similar to HTML but......
Related Websites -
New Loan Funded — Clearing a personal credit card used for business purchases — $9,500 at 18% — A Credit — DTI 46% A new loan funded (Clearing a personal credit card used for business purchases — $9,500 at 18%). I participated via an automatic bid Low AMT -- Extreme DTI -- Autofunding. Which means this funded at less than 15K less than 60% DTI and was autofunding. The borrower had A credit and...... - The US Braces for the Diesel Hybrid Congress has made a offer to car manufacturers which has the auto makers scrambling. They are working to create a short term plan for the release more fuel efficient vehicles into the market in order to help reform the energy situation in the US. This will give automakers aid in......
- 7 Blog Promotion Strategies That Work I just finished looking at my stats and thought I would show you where my traffic is coming from and what marketing tactic I used to get it. Below are only the things that produced visitors to my site in the last 48 hours. Nothing theoretical whatsoever....
- Powerball, Personal Finance, and Library Ethics -- What do you think? Does a book on lottery strategy cross the line into harmful material that a library shouldn't have?...
- Ready for a vacation I'm usually ready for a vacation, but lately the itch to go traveling has been worse than normal. I keep finding all these great deals to fabulous places and I want to go. Now! But I have to be patient, because at this point we don't have the time to......



Add New Comment
Viewing 1 Comment
Thanks. Your comment is awaiting approval by a moderator.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Add New Comment
Trackbacks
(Trackback URL)