Skip to content

Instantly share code, notes, and snippets.

View faithandbrave's full-sized avatar

Akira Takahashi faithandbrave

View GitHub Profile

println のバイナリサイズは何でできているか

std::cout は継承階層が大きいからバイナリが膨らみ、std::println に置き換えれば抑えられる、という言い方をよく耳にする。4つの処理系で測ると、実行ファイルのサイズは printf ≒ cout ≪ println になった。提案文書と実装のコミットを読み直して、この順位がどこから来るのかを調べた記録である。

  • 対象: Apple clang 21.0.0 (libc++ 22.01.06) / clang trunk 24.0.0git e1cf700fe (libc++ 24、ソース 2026-10-07) / Homebrew GCC 14.3.0 / GCC trunk 17.0.0 20260926
  • 環境: arm64-apple-darwin25.6.0 (macOS 26.6.2) / aarch64-unknown-linux-gnu (Docker)
  • 測定日: 2026-11-05

trunk の2つはソースが1か月ほど古いので、「この日付の時点では未対応である」という形の記述に限っている。測ったのは arm64 と aarch64 だけで、x86-64 と MSVC STL は測っていない。macOS と Linux の絶対値は直接比較できない。GCC は main を __text ではなく __text_startup に置くので macOS 側はこの2つを足しており、ELF 側の基準値には CRT の起動コードが含まれる。

noexcept は速いのか

「noexcept を付けた関数は巻き戻し用のスタックを確保しないから速い」という説明を、Apple clang 21 と GCC 14.3 (arm64) で6つの実験にかけた記録。

  • 対象: Apple clang 21.0.0 (clang-2100.4.1.1) / Homebrew GCC 14.3.0
  • 環境: arm64-apple-darwin25.6.0 / macOS 26.6.2
  • 測定日: 2026-11-04

nullチェックはいつ消えるか

実測レポート / 2026-10-23

GCC 14.3.0 (Homebrew) / Apple clang 21.0.0 / arm64 / macOS / -std=c++23 / 42 ケース / 900 回超のコンパイル

「絶対 null にならないポインタの null チェックは、最適化でどれくらい消えるのか」を GCC 14 と Apple clang 21 で測った。最適化レベル、デバッグ情報の有無、LTO、-fno-delete-null-pointer-checks を軸に、生成アセンブリを数えた結果をまとめる。

測り方

import os
import re
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
def find_md_files(base_dir):
for root, dirs, files in os.walk(base_dir):
for file in files:
if file.endswith('.md'):
yield os.path.join(root, file)
import os
import re
# 対象ディレクトリ(スクリプトのあるディレクトリ)
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
# .mdファイルを再帰的に探索
def find_md_files(base_dir):
for root, dirs, files in os.walk(base_dir):
for file in files:
@faithandbrave
faithandbrave / a.md
Last active November 19, 2024 03:27
®
®
@faithandbrave
faithandbrave / link_check.patch
Created November 1, 2024 02:30
リンクチェックにかかった時間を出力するパッチ
import glob
import re
def split_compiler_line(line: str) -> (bool, str, [str]):
compilers = [
"- [Clang](/implementation.md#clang):",
"- [GCC](/implementation.md#gcc):",
"- [ICC](/implementation.md#icc):",
"- [Visual C++](/implementation.md#visual_cpp):",
]
#include <string_view>
#include <memory>
#include <utility>
class life_string_view {
std::string_view _data;
std::shared_ptr<void> _life;
public:
life_string_view(std::string_view sv)
: _data{sv}, _life{} {}
# TODO : cpprefjp以外にも対応する
import glob
import re
import os
import sys
from subprocess import Popen
point_dict = {
"cpprefjp/typo": 1,
"cpprefjp/link": 2,