Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F17726573
t.c
jmg (John-Mark Gurney)
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
jmg
Mar 2 2021, 12:08 AM
2021-03-02 00:08:37 (UTC+0)
Size
1 KB
Referenced Files
None
Subscribers
None
t.c
View Options
#include
<sys/param.h>
#include
<sys/time.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<time.h>
int
sizes
[]
=
{
1
,
10
,
25
,
50
,
100
,
1000
,
10000
,
#if 0
100000,
1000000,
#endif
};
void
verify
(
void
)
{
int
nums
[]
=
{
/* jot -r 20 1 999999999 1 | awk '{ print $1 "," }' */
6513444
,
762838363
,
39044811
,
67968908
,
292366025
,
362679942
,
635992995
,
999568586
,
516833232
,
566881329
,
910796821
,
211509993
,
180633301
,
974333865
,
849253613
,
274059751
,
208859719
,
868674398
,
713667332
,
139342112
,
};
char
*
start
,
*
ptr
;
int
i
,
r
,
val
;
start
=
ptr
=
malloc
(
nitems
(
nums
)
*
10
+
1
);
for
(
i
=
0
;
i
<
nitems
(
nums
);
i
++
)
{
r
=
sprintf
(
ptr
,
"%d"
,
nums
[
i
]);
ptr
+=
r
;
*
ptr
++
=
' '
;
}
*
ptr
++
=
'\x00'
;
printf
(
"verifying: %s
\n
"
,
start
);
ptr
=
start
;
for
(
i
=
0
;
i
<
nitems
(
nums
);
i
++
)
{
sscanf
(
ptr
,
"%d%n"
,
&
val
,
&
r
);
ptr
+=
r
;
if
(
val
!=
nums
[
i
])
{
printf
(
"error! %d != %d
\n
"
,
val
,
nums
[
i
]);
exit
(
1
);
break
;
}
}
}
volatile
int
bin
;
char
*
makelong
(
int
l
)
{
int
i
;
char
*
ret
,
*
pos
;
ret
=
malloc
(
l
*
2
+
1
);
pos
=
ret
;
for
(
i
=
0
;
i
<
l
;
i
++
)
{
*
pos
++
=
'0'
;
*
pos
++
=
' '
;
}
*
pos
++
=
'\x00'
;
return
ret
;
}
void
parsestr
(
char
*
r
)
{
int
cnt
;
int
nchars
;
int
val
;
cnt
=
0
;
while
(
*
r
)
{
sscanf
(
r
,
"%d%n"
,
&
val
,
&
nchars
);
bin
=
val
;
r
+=
nchars
;
cnt
++
;
#if 0
if ((cnt % 10000) == 0)
printf("cnt: %d\n", cnt);
#endif
}
}
void
runsize
(
int
cnt
)
{
struct
timespec
ts
,
te
,
res
;
char
*
nums
;
int
i
;
nums
=
makelong
(
cnt
);
printf
(
"made %d
\n
"
,
cnt
);
clock_gettime
(
CLOCK_MONOTONIC
,
&
ts
);
for
(
i
=
0
;
i
<
500
;
i
++
)
parsestr
(
nums
);
clock_gettime
(
CLOCK_MONOTONIC
,
&
te
);
timespecsub
(
&
te
,
&
ts
,
&
res
);
printf
(
"time: %ld.%09ld
\n
"
,
res
.
tv_sec
,
res
.
tv_nsec
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
i
;
if
(
argc
==
2
)
{
runsize
(
atoi
(
argv
[
1
]));
return
0
;
}
verify
();
for
(
i
=
0
;
i
<
nitems
(
sizes
);
i
++
)
runsize
(
sizes
[
i
]);
}
File Metadata
Details
Attached
Mime Type
text/x-c
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3485775
Default Alt Text
t.c (1 KB)
Attached To
Mode
D29007: address a performance problem w/ partial sscanf on long strings...
Attached
Detach File
Event Timeline
Log In to Comment