-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
38 lines (33 loc) · 868 Bytes
/
Copy pathmain.cpp
File metadata and controls
38 lines (33 loc) · 868 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <benchmark/benchmark.h>
#include <iostream>
void strcpy__(char *a, const char *b) {
while ((*a++ = *b++))
;
}
const char *data = "this string is long enough";
static void BM_strcpy__(benchmark::State &state) {
char arr[256];
while (state.KeepRunning()) {
strcpy__(arr, data);
}
}
BENCHMARK(BM_strcpy__);
static void BM_strcpy__msvc(benchmark::State &state) {
char arr[256];
while (state.KeepRunning()) {
asm volatile(
"mov rdx, %0\n\t"
"sub rdx, %1\n\t"
".LL2strcpy___:\n\t"
"movzx eax, BYTE PTR [%1]\n\t"
"mov BYTE PTR [rdx+%1], al\n\t"
"lea %1, QWORD PTR [%1+1]\n\t"
"test al, al\n\t"
"jne .LL2strcpy___\n\t"
:
: "r"(arr), "r"(data)
: "eax", "cc", "rdx");
}
}
BENCHMARK(BM_strcpy__msvc);
BENCHMARK_MAIN();