C ++ - Does the #pragma once build speed up?

C++, once, pragma

Work on a large project allows in some cases to test some theories concerning a programming language.

It was always interesting if the build is really accelerated by using the #pragma once directive instead of the classic #ifndef #define #endif .

Check this acceleration on a small project is quite problematic, because if the project is going on average for 20 seconds, then we will most likely not see a tangible acceleration, because the assembly time will always float from 17 to 23 seconds.

But I had free time and managed to test this theory on a large project.

Input data

What we have:

  • Question: Will the project build speed change if all #ifndef #define #endif changes in header files to #pragma once
  • To check this, you need to replace defaines with pragma once in 4874 header files.
  • Compiler MSVC 2017

Not to be unsubstantiated, here is a screenshot of a commit from Tortoise Git, which shows the changes in 4874 files

To save all the files, I wrote a python script, I am not the enemy myself, to fix all these files manually. Of course, not everything went smoothly and I had to fix something, but in this case it was not so much work.


In the end, I did not see the difference.

Before the change, the project compiled 15 minutes 52 seconds on average.

After the change, the project was compiled for 15 minutes 50 seconds on average.

If some compilers do optimizations, then this should be included with special flags. In fact, a frontal change does not give anyone an increase in assembly speed.

If you had a reverse experience, please accomplish your goal, and tell me how you achieved speeding up the assembly with #pragma once.

We recommend hosting TIMEWEB
We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.
Support the author Donate


Only authorized users can post comments.
Please, Log in or Sign up
Looking for a Job?
25,000.00 руб. - 30,000.00 руб.
Разработчик Qt/C++
Barnaul, Altai Krai, Russia

For registered users on the site there is a minimum amount of advertising

Sept. 14, 2019, 7:30 a.m.

C++ - Test 001. The first program and data types

  • Result:93points,
  • Rating points8
Sept. 13, 2019, 1:49 p.m.
Ask Questions

C++ - Test 005. Structures and Classes

  • Result:83points,
  • Rating points4
Sept. 12, 2019, 3:42 a.m.

C++ - Test 005. Structures and Classes

  • Result:58points,
  • Rating points-2
Last comments
Sept. 14, 2019, 5:08 p.m.
Misha Lebedev

Приветствую вас Евгений , давно наблюда за развитием вашего замечательного портала, много полезно тут нашел , переодически зачитываюсь. Теперь по сушеству, делаю портал и там идеально ложи…
Sept. 10, 2019, 4:38 p.m.
Evgenij Legotskoj

function view для модели Article и LikeDislike.LIKE будет выглядеть так def like(request, pk): obj = Article.objects.get(pk=pk) try: likedislike = LikeDislike.objects.get(cont…
Sept. 10, 2019, 4:10 p.m.
Oliver Kolesnikov

тут view написан в class based view, если честно ничего не могу разобрать. Как это всё переписать в function view?
Sept. 4, 2019, 3:54 a.m.

thanks for the application, it helps me a lot
Sept. 1, 2019, 2:51 p.m.
Evgenij Legotskoj

Добрый день, Александр. Это Forward Declaration - Предварительное объявление. Позволяет объявить класс без подключения заголовочного файла в заголовочном файле другого класса. Такое об…
Now discuss on the forum
Sept. 16, 2019, 7:09 a.m.

прочитайте https://doc.qt.io/archives/qt-5.11/osx-deployment.html QMAKE_POST_LINK += "~/Qt/5.12.0/clang_64/bin/macdeployqt $${TARGET}.app $$escape_expand( \\n\\t )"
Sept. 16, 2019, 6:41 a.m.

Метод toASCII нельзя применить, а .toHex возвращает block: "000b0500000006006100610061" Но тут есть как минимум несколько букв. Как можно получить не цифры, а текст с цифрами?
Sept. 16, 2019, 2:51 a.m.

У класса есть метод AddPath(). Можно ли передать URL.
Sept. 15, 2019, 7:10 a.m.

Всем привет При выполнении кода под отладкой msvc x64 через некоторое время работы получаю ошибку assert failure in qlist, приложение вылетает. Как правильно настроить qt чтобы при данной о…
Sept. 14, 2019, 8:13 a.m.

Можно использовать Flickable, растнянуть на него картинку и двигать
© EVILEG 2015-2019
Recommend hosting TIMEWEB