-
Notifications
You must be signed in to change notification settings - Fork 25
Description
Hi, first I want to say that the whole concept of building JIT capabilities into the language is excellent. How this should be done is a challenge, but I leave that for the C++ standardization committee.
However, I have been playing around with your fork, branch cxxjit-9.0 and I seem to have an issue with performance.
When I JIT even an empty function in a loop, it is extremely slow compared to a function call. So maybe I'm doing something.
This is the test code:
#include <iostream>
#include <chrono>
static constexpr unsigned int loops = 10000;
template <typename T>
[[clang::jit]] void speed_test() {
(void)0;
}
void trial_jit_speed_test()
{
speed_test<int>();
std::cout << "Speed test" << std::endl;
auto start = std::chrono::steady_clock::now();
for (unsigned int i = 0; i < loops; ++i) {
speed_test<int>();
}
auto end = std::chrono::steady_clock::now();
std::cout << "Elapsed time in nanoseconds: "
<< (double)(end - start).count() / loops
<< " ns" << std::endl;
}
//------------------------------------------------------------------------------------------------------
int main(int argc, char *argv[]) {
trial_jit_speed_test();
}
And I build with the following:
clang++ -fjit -Wall -std=c++17 -march=native -ffast-math -O3 -c speedtest.cc -o speedtest.o
clang++ -fjit -o speedtest speedtest.o
The end result:
Speed test
Elapsed time in nanoseconds: 93.0329 ns
So calling an EMPTY function takes 93 nanoseconds, which is really slow compared to calling a native function. What is going here. I understand the first call is slow as it needs to compile the function. That one is place outside of the loop. But once compiled it should just be a lookup at most.