title: GCC/G++ 预编译头性能优化 date: 2022-04-30 23:33:29 updated: 2022-04-30 23:33:29 categories: 杂项 tags:
最近一直在搞 OJ,为了一个高效的、安全的沙盒编译环境操碎了心,终于实现了一个安全的且对运行影响非常低的沙盒,但是发现程序的编译效率非常的低。
最后通过查阅各种的博客,终于发现了一个非常高效的解决方案
在 OJ 的任务中,很多 ACMer 为了方便起见,经常使用万能头文件 bits/stdc++.h
。
当然这个头文件之前也惹过一次麻烦,就是著名的银川线上赛的 5 元学生机 OJ 事件,使用了 bits/stdc++.h
的编译效率非常低,因为这个头文件本身包含了太多的东西,罗列如下
(推荐直接点目录跳转到下一章)
. /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h
.. /usr/include/c++/7/cassert
... /usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h
.... /usr/include/x86_64-linux-gnu/c++/7/bits/os_defines.h
..... /usr/include/features.h
...... /usr/include/x86_64-linux-gnu/sys/cdefs.h
....... /usr/include/x86_64-linux-gnu/bits/wordsize.h
....... /usr/include/x86_64-linux-gnu/bits/long-double.h
...... /usr/include/x86_64-linux-gnu/gnu/stubs.h
....... /usr/include/x86_64-linux-gnu/gnu/stubs-64.h
.... /usr/include/x86_64-linux-gnu/c++/7/bits/cpu_defines.h
... /usr/include/assert.h
.. /usr/include/c++/7/cctype
... /usr/include/ctype.h
.... /usr/include/x86_64-linux-gnu/bits/types.h
..... /usr/include/x86_64-linux-gnu/bits/wordsize.h
..... /usr/include/x86_64-linux-gnu/bits/typesizes.h
.... /usr/include/endian.h
..... /usr/include/x86_64-linux-gnu/bits/endian.h
..... /usr/include/x86_64-linux-gnu/bits/byteswap.h
...... /usr/include/x86_64-linux-gnu/bits/wordsize.h
...... /usr/include/x86_64-linux-gnu/bits/byteswap-16.h
..... /usr/include/x86_64-linux-gnu/bits/uintn-identity.h
.... /usr/include/x86_64-linux-gnu/bits/types/locale_t.h
..... /usr/include/x86_64-linux-gnu/bits/types/__locale_t.h
.. /usr/include/c++/7/cerrno
... /usr/include/errno.h
.... /usr/include/x86_64-linux-gnu/bits/errno.h
..... /usr/include/linux/errno.h
...... /usr/include/x86_64-linux-gnu/asm/errno.h
....... /usr/include/asm-generic/errno.h
........ /usr/include/asm-generic/errno-base.h
.. /usr/include/c++/7/cfloat
... /usr/lib/gcc/x86_64-linux-gnu/7/include/float.h
.. /usr/include/c++/7/ciso646
.. /usr/include/c++/7/climits
... /usr/lib/gcc/x86_64-linux-gnu/7/include-fixed/limits.h
.... /usr/lib/gcc/x86_64-linux-gnu/7/include-fixed/syslimits.h
..... /usr/lib/gcc/x86_64-linux-gnu/7/include-fixed/limits.h
...... /usr/include/limits.h
....... /usr/include/x86_64-linux-gnu/bits/libc-header-start.h
....... /usr/include/x86_64-linux-gnu/bits/posix1_lim.h
........ /usr/include/x86_64-linux-gnu/bits/local_lim.h
......... /usr/include/linux/limits.h
....... /usr/include/x86_64-linux-gnu/bits/posix2_lim.h
....... /usr/include/x86_64-linux-gnu/bits/xopen_lim.h
........ /usr/include/x86_64-linux-gnu/bits/uio_lim.h
.. /usr/include/c++/7/clocale
... /usr/include/locale.h
.... /usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h
.... /usr/include/x86_64-linux-gnu/bits/locale.h
.. /usr/include/c++/7/cmath
... /usr/include/c++/7/bits/cpp_type_traits.h
... /usr/include/c++/7/ext/type_traits.h
... /usr/include/math.h
.... /usr/include/x86_64-linux-gnu/bits/libc-header-start.h
.... /usr/include/x86_64-linux-gnu/bits/math-vector.h
..... /usr/include/x86_64-linux-gnu/bits/libm-simd-decl-stubs.h
.... /usr/include/x86_64-linux-gnu/bits/floatn.h
..... /usr/include/x86_64-linux-gnu/bits/floatn-common.h
...... /usr/include/x86_64-linux-gnu/bits/long-double.h
.... /usr/include/x86_64-linux-gnu/bits/flt-eval-method.h
.... /usr/include/x86_64-linux-gnu/bits/fp-logb.h
.... /usr/include/x86_64-linux-gnu/bits/fp-fast.h
.... /usr/include/x86_64-linux-gnu/bits/mathcalls-helper-functions.h
.... /usr/include/x86_64-linux-gnu/bits/mathcalls.h
.... /usr/include/x86_64-linux-gnu/bits/mathcalls-helper-functions.h
.... /usr/include/x86_64-linux-gnu/bits/mathcalls.h
.... /usr/include/x86_64-linux-gnu/bits/mathcalls-helper-functions.h
.... /usr/include/x86_64-linux-gnu/bits/mathcalls.h
.... /usr/include/x86_64-linux-gnu/bits/mathcalls.h
.... /usr/include/x86_64-linux-gnu/bits/mathcalls.h
.... /usr/include/x86_64-linux-gnu/bits/mathcalls-helper-functions.h
.... /usr/include/x86_64-linux-gnu/bits/mathcalls.h
.... /usr/include/x86_64-linux-gnu/bits/mathcalls.h
.... /usr/include/x86_64-linux-gnu/bits/mathcalls.h
.... /usr/include/x86_64-linux-gnu/bits/iscanonical.h
... /usr/include/c++/7/bits/std_abs.h
.... /usr/include/stdlib.h
..... /usr/include/x86_64-linux-gnu/bits/libc-header-start.h
..... /usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h
..... /usr/include/x86_64-linux-gnu/bits/waitflags.h
..... /usr/include/x86_64-linux-gnu/bits/waitstatus.h
..... /usr/include/x86_64-linux-gnu/sys/types.h
...... /usr/include/x86_64-linux-gnu/bits/types/clock_t.h
...... /usr/include/x86_64-linux-gnu/bits/types/clockid_t.h
...... /usr/include/x86_64-linux-gnu/bits/types/time_t.h
...... /usr/include/x86_64-linux-gnu/bits/types/timer_t.h
...... /usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h
...... /usr/include/x86_64-linux-gnu/bits/stdint-intn.h
...... /usr/include/x86_64-linux-gnu/sys/select.h
....... /usr/include/x86_64-linux-gnu/bits/select.h
........ /usr/include/x86_64-linux-gnu/bits/wordsize.h
....... /usr/include/x86_64-linux-gnu/bits/types/sigset_t.h
........ /usr/include/x86_64-linux-gnu/bits/types/__sigset_t.h
....... /usr/include/x86_64-linux-gnu/bits/types/struct_timeval.h
....... /usr/include/x86_64-linux-gnu/bits/types/struct_timespec.h
...... /usr/include/x86_64-linux-gnu/sys/sysmacros.h
....... /usr/include/x86_64-linux-gnu/bits/sysmacros.h
...... /usr/include/x86_64-linux-gnu/bits/pthreadtypes.h
....... /usr/include/x86_64-linux-gnu/bits/thread-shared-types.h
........ /usr/include/x86_64-linux-gnu/bits/pthreadtypes-arch.h
......... /usr/include/x86_64-linux-gnu/bits/wordsize.h
..... /usr/include/alloca.h
...... /usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h
..... /usr/include/x86_64-linux-gnu/bits/stdlib-float.h
.. /usr/include/c++/7/csetjmp
... /usr/include/setjmp.h
.... /usr/include/x86_64-linux-gnu/bits/setjmp.h
..... /usr/include/x86_64-linux-gnu/bits/wordsize.h
.. /usr/include/c++/7/csignal
... /usr/include/signal.h
.... /usr/include/x86_64-linux-gnu/bits/signum.h
..... /usr/include/x86_64-linux-gnu/bits/signum-generic.h
.... /usr/include/x86_64-linux-gnu/bits/types/sig_atomic_t.h
.... /usr/include/x86_64-linux-gnu/bits/types/siginfo_t.h
..... /usr/include/x86_64-linux-gnu/bits/wordsize.h
..... /usr/include/x86_64-linux-gnu/bits/types/__sigval_t.h
..... /usr/include/x86_64-linux-gnu/bits/siginfo-arch.h
.... /usr/include/x86_64-linux-gnu/bits/siginfo-consts.h
..... /usr/include/x86_64-linux-gnu/bits/siginfo-consts-arch.h
.... /usr/include/x86_64-linux-gnu/bits/types/sigval_t.h
.... /usr/include/x86_64-linux-gnu/bits/types/sigevent_t.h
..... /usr/include/x86_64-linux-gnu/bits/wordsize.h
.... /usr/include/x86_64-linux-gnu/bits/sigevent-consts.h
.... /usr/include/x86_64-linux-gnu/bits/sigaction.h
.... /usr/include/x86_64-linux-gnu/bits/sigcontext.h
.... /usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h
.... /usr/include/x86_64-linux-gnu/bits/types/stack_t.h
..... /usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h
.... /usr/include/x86_64-linux-gnu/sys/ucontext.h
.... /usr/include/x86_64-linux-gnu/bits/sigstack.h
.... /usr/include/x86_64-linux-gnu/bits/ss_flags.h
.... /usr/include/x86_64-linux-gnu/bits/types/struct_sigstack.h
.... /usr/include/x86_64-linux-gnu/bits/sigthread.h
.. /usr/include/c++/7/cstdarg
... /usr/lib/gcc/x86_64-linux-gnu/7/include/stdarg.h
.. /usr/include/c++/7/cstddef
... /usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h
.. /usr/include/c++/7/cstdio
... /usr/include/stdio.h
.... /usr/include/x86_64-linux-gnu/bits/libc-header-start.h
.... /usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h
.... /usr/include/x86_64-linux-gnu/bits/types/__FILE.h
.... /usr/include/x86_64-linux-gnu/bits/types/FILE.h
.... /usr/include/x86_64-linux-gnu/bits/libio.h
..... /usr/include/x86_64-linux-gnu/bits/_G_config.h
...... /usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h
...... /usr/include/x86_64-linux-gnu/bits/types/__mbstate_t.h
.... /usr/include/x86_64-linux-gnu/bits/stdio_lim.h
.... /usr/include/x86_64-linux-gnu/bits/sys_errlist.h
.. /usr/include/c++/7/cstdlib
.. /usr/include/c++/7/cstring
... /usr/include/string.h
.... /usr/include/x86_64-linux-gnu/bits/libc-header-start.h
.... /usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h
.... /usr/include/strings.h
..... /usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h
.. /usr/include/c++/7/ctime
... /usr/include/time.h
.... /usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h
.... /usr/include/x86_64-linux-gnu/bits/time.h
..... /usr/include/x86_64-linux-gnu/bits/timex.h
.... /usr/include/x86_64-linux-gnu/bits/types/struct_tm.h
.... /usr/include/x86_64-linux-gnu/bits/types/struct_itimerspec.h
.. /usr/include/c++/7/ccomplex
... /usr/include/c++/7/complex
.... /usr/include/c++/7/cmath
.... /usr/include/c++/7/sstream
..... /usr/include/c++/7/istream
...... /usr/include/c++/7/ios
....... /usr/include/c++/7/iosfwd
........ /usr/include/c++/7/bits/stringfwd.h
......... /usr/include/c++/7/bits/memoryfwd.h
........ /usr/include/c++/7/bits/postypes.h
......... /usr/include/c++/7/cwchar
.......... /usr/include/wchar.h
........... /usr/include/x86_64-linux-gnu/bits/libc-header-start.h
........... /usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h
........... /usr/include/x86_64-linux-gnu/bits/wchar.h
........... /usr/include/x86_64-linux-gnu/bits/types/wint_t.h
........... /usr/include/x86_64-linux-gnu/bits/types/mbstate_t.h
....... /usr/include/c++/7/exception
........ /usr/include/c++/7/bits/exception.h
........ /usr/include/c++/7/bits/exception_ptr.h
......... /usr/include/c++/7/bits/exception_defines.h
......... /usr/include/c++/7/bits/cxxabi_init_exception.h
.......... /usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h
......... /usr/include/c++/7/typeinfo
.......... /usr/include/c++/7/bits/hash_bytes.h
......... /usr/include/c++/7/new
.......... /usr/include/c++/7/exception
........ /usr/include/c++/7/bits/nested_exception.h
......... /usr/include/c++/7/bits/move.h
.......... /usr/include/c++/7/bits/concept_check.h
.......... /usr/include/c++/7/type_traits
....... /usr/include/c++/7/bits/char_traits.h
........ /usr/include/c++/7/bits/stl_algobase.h
......... /usr/include/c++/7/bits/functexcept.h
......... /usr/include/c++/7/ext/numeric_traits.h
......... /usr/include/c++/7/bits/stl_pair.h
......... /usr/include/c++/7/bits/stl_iterator_base_types.h
......... /usr/include/c++/7/bits/stl_iterator_base_funcs.h
.......... /usr/include/c++/7/debug/assertions.h
......... /usr/include/c++/7/bits/stl_iterator.h
.......... /usr/include/c++/7/bits/ptr_traits.h
......... /usr/include/c++/7/debug/debug.h
......... /usr/include/c++/7/bits/predefined_ops.h
........ /usr/include/c++/7/cwchar
........ /usr/include/c++/7/cstdint
......... /usr/lib/gcc/x86_64-linux-gnu/7/include/stdint.h
.......... /usr/include/stdint.h
........... /usr/include/x86_64-linux-gnu/bits/libc-header-start.h
........... /usr/include/x86_64-linux-gnu/bits/wordsize.h
........... /usr/include/x86_64-linux-gnu/bits/stdint-uintn.h
....... /usr/include/c++/7/bits/localefwd.h
........ /usr/include/x86_64-linux-gnu/c++/7/bits/c++locale.h
......... /usr/include/c++/7/clocale
........ /usr/include/c++/7/cctype
....... /usr/include/c++/7/bits/ios_base.h
........ /usr/include/c++/7/ext/atomicity.h
......... /usr/include/x86_64-linux-gnu/c++/7/bits/gthr.h
.......... /usr/include/x86_64-linux-gnu/c++/7/bits/gthr-default.h
........... /usr/include/pthread.h
............ /usr/include/sched.h
............. /usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h
............. /usr/include/x86_64-linux-gnu/bits/sched.h
............. /usr/include/x86_64-linux-gnu/bits/cpu-set.h
............ /usr/include/x86_64-linux-gnu/bits/wordsize.h
......... /usr/include/x86_64-linux-gnu/c++/7/bits/atomic_word.h
........ /usr/include/c++/7/bits/locale_classes.h
......... /usr/include/c++/7/string
.......... /usr/include/c++/7/bits/allocator.h
........... /usr/include/x86_64-linux-gnu/c++/7/bits/c++allocator.h
............ /usr/include/c++/7/ext/new_allocator.h
.......... /usr/include/c++/7/bits/ostream_insert.h
........... /usr/include/c++/7/bits/cxxabi_forced.h
.......... /usr/include/c++/7/bits/stl_function.h
........... /usr/include/c++/7/backward/binders.h
.......... /usr/include/c++/7/bits/range_access.h
........... /usr/include/c++/7/initializer_list
.......... /usr/include/c++/7/bits/basic_string.h
........... /usr/include/c++/7/ext/alloc_traits.h
............ /usr/include/c++/7/bits/alloc_traits.h
........... /usr/include/c++/7/ext/string_conversions.h
............ /usr/include/c++/7/cstdlib
............ /usr/include/c++/7/cwchar
............ /usr/include/c++/7/cstdio
............ /usr/include/c++/7/cerrno
........... /usr/include/c++/7/bits/functional_hash.h
.......... /usr/include/c++/7/bits/basic_string.tcc
......... /usr/include/c++/7/bits/locale_classes.tcc
........ /usr/include/c++/7/system_error
......... /usr/include/x86_64-linux-gnu/c++/7/bits/error_constants.h
.......... /usr/include/c++/7/cerrno
......... /usr/include/c++/7/stdexcept
....... /usr/include/c++/7/streambuf
........ /usr/include/c++/7/bits/streambuf.tcc
....... /usr/include/c++/7/bits/basic_ios.h
........ /usr/include/c++/7/bits/locale_facets.h
......... /usr/include/c++/7/cwctype
.......... /usr/include/wctype.h
........... /usr/include/x86_64-linux-gnu/bits/wctype-wchar.h
......... /usr/include/c++/7/cctype
......... /usr/include/x86_64-linux-gnu/c++/7/bits/ctype_base.h
......... /usr/include/c++/7/bits/streambuf_iterator.h
......... /usr/include/x86_64-linux-gnu/c++/7/bits/ctype_inline.h
......... /usr/include/c++/7/bits/locale_facets.tcc
........ /usr/include/c++/7/bits/basic_ios.tcc
...... /usr/include/c++/7/ostream
....... /usr/include/c++/7/bits/ostream.tcc
...... /usr/include/c++/7/bits/istream.tcc
..... /usr/include/c++/7/bits/sstream.tcc
.. /usr/include/c++/7/cfenv
... /usr/include/c++/7/fenv.h
.... /usr/include/fenv.h
..... /usr/include/x86_64-linux-gnu/bits/libc-header-start.h
..... /usr/include/x86_64-linux-gnu/bits/fenv.h
.. /usr/include/c++/7/cinttypes
... /usr/include/inttypes.h
.. /usr/include/c++/7/cstdalign
... /usr/lib/gcc/x86_64-linux-gnu/7/include/stdalign.h
.. /usr/include/c++/7/cstdbool
... /usr/lib/gcc/x86_64-linux-gnu/7/include/stdbool.h
.. /usr/include/c++/7/ctgmath
... /usr/include/c++/7/cmath
.. /usr/include/c++/7/cuchar
... /usr/include/c++/7/cwchar
... /usr/include/uchar.h
.... /usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h
.. /usr/include/c++/7/cwchar
.. /usr/include/c++/7/cwctype
.. /usr/include/c++/7/algorithm
... /usr/include/c++/7/utility
.... /usr/include/c++/7/bits/stl_relops.h
... /usr/include/c++/7/bits/stl_algo.h
.... /usr/include/c++/7/cstdlib
.... /usr/include/c++/7/bits/algorithmfwd.h
.... /usr/include/c++/7/bits/stl_heap.h
.... /usr/include/c++/7/bits/stl_tempbuf.h
..... /usr/include/c++/7/bits/stl_construct.h
.... /usr/include/c++/7/bits/uniform_int_dist.h
..... /usr/include/c++/7/limits
.. /usr/include/c++/7/bitset
.. /usr/include/c++/7/deque
... /usr/include/c++/7/bits/stl_uninitialized.h
... /usr/include/c++/7/bits/stl_deque.h
... /usr/include/c++/7/bits/deque.tcc
.. /usr/include/c++/7/fstream
... /usr/include/c++/7/bits/codecvt.h
... /usr/include/c++/7/cstdio
... /usr/include/x86_64-linux-gnu/c++/7/bits/basic_file.h
.... /usr/include/x86_64-linux-gnu/c++/7/bits/c++io.h
..... /usr/include/c++/7/cstdio
... /usr/include/c++/7/bits/fstream.tcc
.. /usr/include/c++/7/functional
... /usr/include/c++/7/tuple
.... /usr/include/c++/7/array
.... /usr/include/c++/7/bits/uses_allocator.h
.... /usr/include/c++/7/bits/invoke.h
... /usr/include/c++/7/bits/std_function.h
.... /usr/include/c++/7/bits/refwrap.h
.. /usr/include/c++/7/iomanip
... /usr/include/c++/7/locale
.... /usr/include/c++/7/bits/locale_facets_nonio.h
..... /usr/include/c++/7/ctime
..... /usr/include/x86_64-linux-gnu/c++/7/bits/time_members.h
..... /usr/include/x86_64-linux-gnu/c++/7/bits/messages_members.h
...... /usr/include/libintl.h
..... /usr/include/c++/7/bits/locale_facets_nonio.tcc
.... /usr/include/c++/7/bits/locale_conv.h
..... /usr/include/c++/7/bits/stringfwd.h
..... /usr/include/c++/7/bits/allocator.h
..... /usr/include/c++/7/bits/codecvt.h
..... /usr/include/c++/7/bits/unique_ptr.h
... /usr/include/c++/7/bits/quoted_string.h
.. /usr/include/c++/7/iostream
.. /usr/include/c++/7/iterator
... /usr/include/c++/7/bits/stream_iterator.h
.. /usr/include/c++/7/list
... /usr/include/c++/7/bits/stl_list.h
.... /usr/include/c++/7/bits/allocated_ptr.h
.... /usr/include/c++/7/ext/aligned_buffer.h
... /usr/include/c++/7/bits/list.tcc
.. /usr/include/c++/7/map
... /usr/include/c++/7/bits/stl_tree.h
... /usr/include/c++/7/bits/stl_map.h
... /usr/include/c++/7/bits/stl_multimap.h
.. /usr/include/c++/7/memory
... /usr/include/c++/7/bits/stl_raw_storage_iter.h
... /usr/include/c++/7/ext/concurrence.h
... /usr/include/c++/7/bits/unique_ptr.h
... /usr/include/c++/7/bits/shared_ptr.h
.... /usr/include/c++/7/bits/shared_ptr_base.h
... /usr/include/c++/7/bits/shared_ptr_atomic.h
.... /usr/include/c++/7/bits/atomic_base.h
..... /usr/include/c++/7/bits/atomic_lockfree_defines.h
... /usr/include/c++/7/backward/auto_ptr.h
.. /usr/include/c++/7/numeric
... /usr/include/c++/7/bits/stl_numeric.h
.. /usr/include/c++/7/queue
... /usr/include/c++/7/vector
.... /usr/include/c++/7/bits/stl_vector.h
.... /usr/include/c++/7/bits/stl_bvector.h
.... /usr/include/c++/7/bits/vector.tcc
... /usr/include/c++/7/bits/stl_queue.h
.. /usr/include/c++/7/set
... /usr/include/c++/7/bits/stl_set.h
... /usr/include/c++/7/bits/stl_multiset.h
.. /usr/include/c++/7/stack
... /usr/include/c++/7/bits/stl_stack.h
.. /usr/include/c++/7/valarray
... /usr/include/c++/7/cmath
... /usr/include/c++/7/bits/valarray_array.h
.... /usr/include/c++/7/cstdlib
.... /usr/include/c++/7/bits/valarray_array.tcc
... /usr/include/c++/7/bits/valarray_before.h
.... /usr/include/c++/7/bits/slice_array.h
... /usr/include/c++/7/bits/valarray_after.h
... /usr/include/c++/7/bits/gslice.h
... /usr/include/c++/7/bits/gslice_array.h
... /usr/include/c++/7/bits/mask_array.h
... /usr/include/c++/7/bits/indirect_array.h
.. /usr/include/c++/7/atomic
.. /usr/include/c++/7/chrono
... /usr/include/c++/7/ratio
... /usr/include/c++/7/ctime
... /usr/include/c++/7/bits/parse_numbers.h
.. /usr/include/c++/7/codecvt
.. /usr/include/c++/7/condition_variable
... /usr/include/c++/7/bits/std_mutex.h
.. /usr/include/c++/7/forward_list
... /usr/include/c++/7/bits/forward_list.h
... /usr/include/c++/7/bits/forward_list.tcc
.. /usr/include/c++/7/future
... /usr/include/c++/7/mutex
... /usr/include/c++/7/thread
.... /usr/include/c++/7/cerrno
... /usr/include/c++/7/bits/atomic_futex.h
.. /usr/include/c++/7/random
... /usr/include/c++/7/cmath
... /usr/include/c++/7/cstdlib
... /usr/include/c++/7/bits/random.h
... /usr/include/x86_64-linux-gnu/c++/7/bits/opt_random.h
... /usr/include/c++/7/bits/random.tcc
.. /usr/include/c++/7/regex
... /usr/include/c++/7/cstring
... /usr/include/c++/7/bits/regex_constants.h
... /usr/include/c++/7/bits/regex_error.h
... /usr/include/c++/7/bits/regex_automaton.h
.... /usr/include/c++/7/bits/regex_automaton.tcc
... /usr/include/c++/7/bits/regex_scanner.h
.... /usr/include/c++/7/bits/regex_scanner.tcc
... /usr/include/c++/7/bits/regex_compiler.h
.... /usr/include/c++/7/bits/regex_compiler.tcc
... /usr/include/c++/7/bits/regex.h
.... /usr/include/c++/7/bits/regex.tcc
... /usr/include/c++/7/bits/regex_executor.h
.... /usr/include/c++/7/bits/regex_executor.tcc
.. /usr/include/c++/7/scoped_allocator
.. /usr/include/c++/7/typeindex
.. /usr/include/c++/7/unordered_map
... /usr/include/c++/7/bits/hashtable.h
.... /usr/include/c++/7/bits/hashtable_policy.h
... /usr/include/c++/7/bits/unordered_map.h
.. /usr/include/c++/7/unordered_set
... /usr/include/c++/7/bits/unordered_set.h
.. /usr/include/c++/7/shared_mutex
大概就这些。。。
查阅后发现其实 GCC/G++ 可以预编译头文件的,简单来说就是直接编译头文件成 gch 文件即可,即
cd /usr/include/x86_64-linux-gnu/c++/9/bits
sudo g++ -std=c++17 stdc++.h
而后正常使用编译命令即可,GCC/G++ 会自动使用预编译的内容
同样的命令,同样的代码,仅使用了 bits/stdc++.h
的情况下,两者的耗时情况
先是不使用预编译的
real 0m2.476s
user 0m1.279s
sys 0m0.154s
差不多 4s 的耗时
然后是使用来预编译的
real 0m0.668s
user 0m0.258s
sys 0m0.065s
差不多 1s 的耗时
天差地别