From owner-freebsd-performance@FreeBSD.ORG Mon Jun 2 08:26:28 2008 Return-Path: Delivered-To: freebsd-performance@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D285B1065672 for ; Mon, 2 Jun 2008 08:26:28 +0000 (UTC) (envelope-from kometen@gmail.com) Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.154]) by mx1.freebsd.org (Postfix) with ESMTP id 4FCD38FC18 for ; Mon, 2 Jun 2008 08:26:28 +0000 (UTC) (envelope-from kometen@gmail.com) Received: by fg-out-1718.google.com with SMTP id l26so820232fgb.35 for ; Mon, 02 Jun 2008 01:26:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=OWY0TxNhP9LmqWGcTro5Q0oovC0m6vsoY/UvrEJV0MM=; b=NFnmWa/jOQ0xJODOK4EuX1WWRU+B+nJ84488pKnWD2cqvh50klDSOFT+MaV+xnBg0OfPVcMnBGV5vvxbtm3I0HCDoo6iHsLreA8bt5uF7+WRNaNJ+ksU6XfHhF55XJQ2J+ycfR3arUtx0VMkcAP93pkBIgRw9TUf+6yM+cLoaig= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=IMOMHAbIbwwOnFLZijTISsWjFq6KcWkKlw6HbUfpTpVlXHyOXtBW3i+ztNwIH/V89fask+cZ18q3nKVIv53Bw5+17wkqMvmqE28h/yUdBbh+BY+KtJY5A86FrBfNfqiQNJzxGt2B9KYFY4MSADM39Kl0hT3cUNCq72VB4xfPDoY= Received: by 10.86.4.2 with SMTP id 2mr5955365fgd.16.1212393678453; Mon, 02 Jun 2008 01:01:18 -0700 (PDT) Received: by 10.86.79.5 with HTTP; Mon, 2 Jun 2008 01:01:18 -0700 (PDT) Message-ID: Date: Mon, 2 Jun 2008 10:01:18 +0200 From: "Claus Guttesen" To: "Sean Chittenden" In-Reply-To: <2B465A44-2578-4675-AA17-EBE17A072017@chittenden.org> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <2B465A44-2578-4675-AA17-EBE17A072017@chittenden.org> Cc: freebsd-performance@freebsd.org Subject: Re: Micro-benchmark for various time syscalls... X-BeenThere: freebsd-performance@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Performance/tuning List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Jun 2008 08:26:28 -0000 > I wrote a small micro-benchmark utility[1] to test various time syscalls and > the results were a bit surprising to me. The results were from a UP machine > and I believe that the difference between gettimeofday(2) and > clock_gettime(CLOCK_REALTIME_FAST) would've been bigger on an SMP system and > performance would've degraded further with each additional core. > > clock_gettime(CLOCK_REALTIME_FAST) is likely the ideal function for most > authors (CLOCK_REALTIME_FAST is supposed to be precise to +/- 10ms of > CLOCK_REALTIME's value[2]). In fact, I'd assume that CLOCK_REALTIME_FAST is > just as accurate as Linux's gettimeofday(2) (a statement I can't back up, > but believe is likely to be correct) and therefore there isn't much harm (if > any) in seeing clock_gettime(2) + CLOCK_REALTIME_FAST receive more > widespread use vs. gettimeofday(2). FYI. -sc > > PS Is there a reason that time(3) can't be implemented in terms of > clock_gettime(CLOCK_SECOND)? 10ms seems precise enough compared to time_t's > whole second resolution. > > % ./bench_time 9079882 | sort -rnk1 > Timing micro-benchmark. 9079882 syscall iterations. > Avg. us/call Elapsed Name > 9.322484 84.647053 gettimeofday(2) > 8.955324 81.313291 time(3) > 8.648315 78.525684 clock_gettime(2/CLOCK_REALTIME) > 8.598495 78.073325 clock_gettime(2/CLOCK_MONOTONIC) > 0.674194 6.121600 clock_gettime(2/CLOCK_PROF) > 0.648083 5.884515 clock_gettime(2/CLOCK_VIRTUAL) > 0.330556 3.001412 clock_gettime(2/CLOCK_REALTIME_FAST) > 0.306514 2.783111 clock_gettime(2/CLOCK_SECOND) > 0.262788 2.386085 clock_gettime(2/CLOCK_MONOTONIC_FAST) > Last value from gettimeofday(2): 1212380080.620649 > Last value from time(3): 1212380161 > Last value from clock_gettime(2/CLOCK_VIRTUAL): 2.296430000 > Last value from clock_gettime(2/CLOCK_SECOND): 1212380338.000000000 > Last value from clock_gettime(2/CLOCK_REALTIME_FAST): 1212380243.461081040 > Last value from clock_gettime(2/CLOCK_REALTIME): 1212380240.459788612 > Last value from clock_gettime(2/CLOCK_PROF): 185.560343000 > Last value from clock_gettime(2/CLOCK_MONOTONIC_FAST): 5747219.271879584 > Last value from clock_gettime(2/CLOCK_MONOTONIC): 5747216.886509281 rozetta~/devel/c%>sysctl hw.model hw.model: Intel(R) Xeon(R) CPU E5345 @ 2.33GHz rozetta~/devel/c%>./bench_time 9079882 | sort -rnk1 Timing micro-benchmark. 9079882 syscall iterations. Avg. us/call Elapsed Name 1.405469 12.761494 clock_gettime(2/CLOCK_REALTIME) 1.313101 11.922799 time(3) 1.305518 11.853953 clock_gettime(2/CLOCK_MONOTONIC) 1.303947 11.839681 gettimeofday(2) 0.442908 4.021557 clock_gettime(2/CLOCK_PROF) 0.436484 3.963223 clock_gettime(2/CLOCK_VIRTUAL) 0.217718 1.976851 clock_gettime(2/CLOCK_MONOTONIC_FAST) 0.215264 1.954571 clock_gettime(2/CLOCK_REALTIME_FAST) 0.211779 1.922932 clock_gettime(2/CLOCK_SECOND) Value from time(3): 1212391638 Last value from gettimeofday(2): 1212391626.146308 Last value from clock_gettime(2/CLOCK_VIRTUAL): 4.179847000 Last value from clock_gettime(2/CLOCK_SECOND): 1212391676.000000000 Last value from clock_gettime(2/CLOCK_REALTIME_FAST): 1212391652.785214038 Last value from clock_gettime(2/CLOCK_REALTIME): 1212391650.830730996 Last value from clock_gettime(2/CLOCK_PROF): 60.276182000 Last value from clock_gettime(2/CLOCK_MONOTONIC_FAST): 1190915.000747909 Last value from clock_gettime(2/CLOCK_MONOTONIC): 1190913.024357334 gettimeofday is 6 times slower on this system, 28 times slower on your system. -- regards Claus When lenity and cruelty play for a kingdom, the gentlest gamester is the soonest winner. Shakespeare