Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JIT really slow #31

Open
cnergyone opened this issue Jan 31, 2022 · 0 comments
Open

JIT really slow #31

cnergyone opened this issue Jan 31, 2022 · 0 comments

Comments

@cnergyone
Copy link

cnergyone commented Jan 31, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant