[Python-Dev] 51 Million calls to _PyUnicodeUCS2_IsLinebreak() (???)
"Martin v. Löwis"
martin at v.loewis.de
Wed Aug 24 12:56:58 CEST 2005
M.-A. Lemburg wrote:
> I think it's worthwhile reconsidering this approach for
> character type queries that do no involve a huge number
> of code points.
I would advise against that. I measure both versions
(your version called PyUnicode_IsLinebreak2) with the
volatile int result;
#define REPS 10000000000LL
long long i;
s1 = clock();
result = _PyUnicode_IsLinebreak('(');
s2 = clock();
result = PyUnicode_IsLinebreak2('(');
s3 = clock();
result = _PyUnicode_IsLinebreak('\n');
s4 = clock();
result = PyUnicode_IsLinebreak2('\n');
s5 = clock();
printf("f1, (: %d\nf2, (: %d\nf1, CR: %d\n, f2, CR: %d\n",
and got those numbers
f1, (: 13210000
f2, (: 13300000
f1, CR: 13220000
, f2, CR: 13250000
What can be seen is that performance the two versions is nearly
identical, with the code currently used being slightly better.
What can also be seen is that, on my machine, 1e10 calls to
IsLinebreak take 13.2 seconds. So 51 Mio calls take about 70ms.
The reported performance problem is more likely in the allocation
of all these splitlines results, and the copying of the same
strings over and over again.
More information about the Python-Dev