tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: CVS commit: src/lib/libc/string
In article <20080924152816.9680C5654E%rebar.astron.com@localhost>,
Christos Zoulas <christos%zoulas.com@localhost> wrote:
>On Sep 24, 5:09pm, netbsd%lists.veego.de@localhost (Bernd Ernesti) wrote:
>-- Subject: Re: CVS commit: src/lib/libc/string
>
>| On Wed, Sep 24, 2008 at 02:36:02PM +0000, Christos Zoulas wrote:
>| >
>| > Module Name: src
>| > Committed By: christos
>| > Date: Wed Sep 24 14:36:02 UTC 2008
>| >
>| > Modified Files:
>| > src/lib/libc/string: strpbrk.c
>| >
>| > Log Message:
>| > From Ilya Dogolazky ilya.dogolazky at teleca dot fi:
>| >
>| > The new algorithm does not use any array initialisation.
>| > Instead of that the only integer variable "index" is initialized.
>| > It is not using any bitwise operations and shifts as well.
>|
>| And what about the concerns and questions that were raised on tech-userlevel?
>
>Will be addressed. I just wanted to get the code in.
The new code wins with gcc -O2, loses with gcc -O.
christos
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#define ITERATIONS 10000
extern void foo(const char *, const char *);
extern void bar(const char *, const char *);
static size_t
incr(size_t x)
{
return x < 100 ? 10 :
x < 1000 ? 100 :
1000;
}
static void
garbage(char *buf, size_t len)
{
buf[len] = '\0';
while (len--)
while ((buf[len] = (unsigned char)rand()) == '\0')
continue;
}
int
main(int argc, char *argv[])
{
size_t m, n, i;
char ms[10240], ns[10240], *p;
#ifdef CLOCK_REALTIME
struct timespec beforefoo, afterfoo, beforebar, afterbar;
#else
struct timeval beforefoo, afterfoo, beforebar, afterbar;
#endif
for (m = 1; m < sizeof(ms); m += incr(m)) {
srand(1);
garbage(ms, m);
for (n = 1; n < sizeof(ns); n += incr(n)) {
garbage(ns, n);
#ifdef CLOCK_REALTIME
clock_gettime(CLOCK_REALTIME, &beforefoo);
#else
gettimeofday(&beforefoo, NULL);
#endif
for (i = 0; i < ITERATIONS; i++)
foo(ms, ns);
#ifdef CLOCK_REALTIME
clock_gettime(CLOCK_REALTIME, &afterfoo);
timespecsub(&afterfoo, &beforefoo, &afterfoo);
#else
gettimeofday(&afterfoo, NULL);
timersub(&afterfoo, &beforefoo, &afterfoo);
#endif
#ifdef CLOCK_REALTIME
clock_gettime(CLOCK_REALTIME, &beforebar);
#else
gettimeofday(&beforebar, NULL);
#endif
for (i = 0; i < ITERATIONS; i++)
bar(ms, ns);
#ifdef CLOCK_REALTIME
clock_gettime(CLOCK_REALTIME, &afterbar);
timespecsub(&afterbar, &beforebar, &afterbar);
#else
gettimeofday(&afterbar, NULL);
timersub(&afterbar, &beforebar, &afterbar);
#endif
printf("%.3d, %.3d: %lld.%lld %lld.%lld\n", m, n,
(long long)afterfoo.tv_sec,
#ifdef CLOCK_REALTIME
(long long)afterfoo.tv_nsec,
#else
(long long)afterfoo.tv_usec,
#endif
(long long)afterbar.tv_sec,
#ifdef CLOCK_REALTIME
(long long)afterbar.tv_nsec);
#else
(long long)afterbar.tv_usec);
#endif
}
}
return 0;
}
Home |
Main Index |
Thread Index |
Old Index