This seems to me like a reasonable thing to want to optimize and a
reasonable general approach. I think you'll have better luck getting
something done if you upload a CL:
http://golang.org/doc/contribute.html
I'd also suggest fixing style inconsistencies before uploading.
- Evan
I would have said not, seeing as the code for slicing a string includes
(I paraphrase)
result.stringpointer = incoming.stringpointer + delta;
So no guarantee.
Chris
--
Chris "allusive" Dollin
sorry, it was kind of a rhetorical question.
evan's optimisation won't work on architectures that
disallow unaligned word access.
First, cmpstring is written simply and portably but it's probably worth writing architecture-dependent code for it, since it comes up a lot.
Second, and much more important, it's clear that cmpstring should be specialized for equality, since a==b can usually be detected as false due simply to the length, while cmpstring will examine all the bytes. This is the real optimization to make.
-rob
As Rob says, a case you're ignoring is strings of
different length. strequal should say
return a->len == b->len && memcmp(a->str, b->str, a->len) == 0;
and then just make memcmp better.
The implementation of better may differ per architecture.
The x86 is pretty good about unaligned accesses in
this case, but the simple C code might be best for
something like ARM.
Your benchmarks are fighting the benchmark system.
If you drop the numIterations parameter and instead use b.N
as the iteration count, you'll find that the numbers are then
comparable.
Russ