From owner-freebsd-hackers@FreeBSD.ORG Thu Jan 20 14:21:28 2005 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5F70C16A4CE for ; Thu, 20 Jan 2005 14:21:28 +0000 (GMT) Received: from smtpx.spintech.ro (smtpx.spintech.ro [81.181.24.231]) by mx1.FreeBSD.org (Postfix) with ESMTP id E242B43D5F for ; Thu, 20 Jan 2005 14:21:27 +0000 (GMT) (envelope-from aanton@spintech.ro) Received: from smtpx.spintech.ro (antivirus [15.0.0.1]) by smtpx.spintech.ro (Postfix) with ESMTP id 5C3983A4F2; Thu, 20 Jan 2005 13:04:23 +0000 (UTC) Received: from [10.0.0.2] (beastie [10.0.0.2]) by smtpx.spintech.ro (Postfix) with ESMTP id 31C603A4DB; Thu, 20 Jan 2005 13:04:23 +0000 (UTC) Message-ID: <41EFBEA5.50007@spintech.ro> Date: Thu, 20 Jan 2005 16:22:29 +0200 From: Alin-Adrian Anton User-Agent: Mozilla Thunderbird 1.0 (X11/20041229) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Marco Trentini References: <20050120004406.GF921@einstein.lab> In-Reply-To: <20050120004406.GF921@einstein.lab> X-Enigmail-Version: 0.89.5.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Open-Source: www.opensource.org cc: freebsd-hackers@freebsd.org Subject: Re: clock time in milliseconds into a c program X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Jan 2005 14:21:28 -0000 Marco Trentini wrote: > Hi, I need to clock the function execution time into a C > program. I know /usr/include/time.h library but I need to > clock the time in milliseconds. > > Any suggestions, links? > ---snip--- #include struct timeval tv1,tv2; struct timezone tz1,tz2; gettimeofday(&tv1,&tz1); for (i=0;i<5000000;i++) { tmp=tree_insert(myroot,i,i+10); // cycles if (tmp) myroot=tmp; // cycles } gettimeofday(&tv2,&tz2); fprintf(stderr,"Insertion of 5 billions lasted %d microseconds\n", ((tv2.tv_sec - tv1.tv_sec) * 1000000 + (tv2.tv_usec - tv1.tv_usec))); ---snip--- So you can measure the cycles multiple times then compute the average time. For this snippet (which deals with a B+tree) i got results of the form 0.3445866564 microseconds, which means 344.5867 miliseconds.. etc.. I don't think there is a streight way to speed-up the default unix time resolution, which is, as far as i know, in microseconds. Regards, -- Alin-Adrian Anton GPG keyID 0x1E2FFF2E (2963 0C11 1AF1 96F6 0030 6EE9 D323 639D 1E2F FF2E) gpg --keyserver pgp.mit.edu --recv-keys 1E2FFF2E Never ask a man what OS he uses. If it's FreeBSD, he'll tell you. If it's not, why embarrass him? ..I'm sorry..