Evgenii Legotckoi
Oct. 10, 2018, 7:32 p.m.

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

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.

Conclusion

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.

Recommended articles on this topic

By article asked0question(s)

1

Do you like it? Share on social networks!

Comments

Only authorized users can post comments.
Please, Log in or Sign up
  • Last comments
  • Evgenii Legotckoi
    March 9, 2025, 9:02 p.m.
    К сожалению, я этого подсказать не могу, поскольку у меня нет необходимости в обходе блокировок и т.д. Поэтому я и не задавался решением этой проблемы. Ну выглядит так, что вам действитель…
  • VP
    March 9, 2025, 4:14 p.m.
    Здравствуйте! Я устанавливал Qt6 из исходников а также Qt Creator по отдельности. Все компоненты, связанные с разработкой для Android, установлены. Кроме одного... Когда пытаюсь скомпилиров…
  • ИМ
    Nov. 22, 2024, 9:51 p.m.
    Добрый вечер Евгений! Я сделал себе авторизацию аналогичную вашей, все работает, кроме возврата к предидущей странице. Редеректит всегда на главную, хотя в логах сервера вижу запросы на правильн…
  • Evgenii Legotckoi
    Oct. 31, 2024, 11:37 p.m.
    Добрый день. Да, можно. Либо через такие же плагины, либо с постобработкой через python библиотеку Beautiful Soup
  • A
    Oct. 19, 2024, 5:19 p.m.
    Подскажите как это запустить? Я не шарю в программировании и кодинге. Скачал и установаил Qt, но куча ошибок выдается и не запустить. А очень надо fb3 переконвертировать в html