[llvm] [llvm] Improve implementation of StringRef::find_last_of and cie (PR #71865)

via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 6 12:54:53 PST 2024


serge-sans-paille wrote:

Code updated, and I ran the following micro benchmark:

```
$ cat a.cpp
#include "llvm/ADT/StringRef.h"
#include <cstdlib>

int main(int argc, char ** argv) {
  long n = atol(argv[2]);
  char * data = argv[1];
  llvm::StringRef S(data);
  size_t k = 0;
  for (long i = 0; i < n; ++i)
    k+= S.find_last_of("\r\n");
  return k;
}
$ clang++ a.cpp -fPIC -o a -O2 -lLLVM -L$PWD/lib
$ LD_LIBRARY_PATH=$PWD/lib ./a "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" 10000000
```

which is as stupid as a micro benchmark can be. This patch make it run twice as fast as the non-patched version.

https://github.com/llvm/llvm-project/pull/71865


More information about the llvm-commits mailing list