- हाई-परफॉर्मेंस C/C++ और assembly coding techniques को व्यावहारिक उदाहरणों के साथ सीखने के लिए एक open source प्रोजेक्ट
- STL की जगह optimized libraries और विभिन्न hardware optimization techniques के उपयोग के उदाहरण शामिल
- input generation cost, math function approximation, CPU branch prediction, multicore parallelization जैसी कई performance tricks की व्याख्या
- CUDA, PTX, ASM, FPGA, JSON processing जैसी platform-specific optimization techniques से लेकर benchmark measurement methods तक का व्यापक कवरेज
- Google Benchmark आधारित benchmark execution और statistical processing automation सुविधा प्रदान करता है
परफॉर्मेंस-केंद्रित C/C++ और assembly code लिखने का तरीका
- यह प्रोजेक्ट हाई-परफॉर्मेंस software design के लिए जरूरी intuition और mindset विकसित करने में मदद करने वाला benchmark code collection है
- आधुनिक code में आम bugs, security issues, performance bottlenecks से बचने के लिए व्यावहारिक coding examples शामिल हैं
- university lectures या bootcamps में आसानी से न मिलने वाली real-world performance-oriented techniques को व्यवस्थित रूप से पेश करता है
- अधिकांश code GCC, Clang आधारित Linux environment में चलता है, लेकिन Windows और macOS का भी आंशिक समर्थन है
- हाई-परफॉर्मेंस code implementation के लिए parallel algorithms, coroutines, polymorphism आदि का भी परिचय देता है
मुख्य विषय
- क्या random input 100 गुना सस्ता हो सकता है?! यह तथ्य कि input generation algorithm से भी धीमा हो सकता है
- 1% error पर cost सिर्फ 1/40:
std::sin जैसी STL trigonometric functions को केवल 3 lines of code में approximate करके देखें
- क्या lazy logic 4 गुना तेज हो सकती है? custom
std::ranges और iterators के साथ चरम laziness लागू करना
-O3 से आगे की compiler optimization: hidden flags और tricks से performance को 2 गुना तक और बढ़ाया जा सकता है
- क्या matrix multiplication ही समस्या है? operations 60% कम होने पर भी 3x3x3 GEMM, 4x4x4 से 70% धीमा हो सकता है
- AI scaling की सच्चाई? theoretical ALU throughput और वास्तविक BLAS performance के बीच के अंतर को मापना
- कितने conditionals बहुत ज़्यादा माने जाएँगे? सिर्फ 10 lines of code में CPU branch predictor की सीमाओं का प्रयोग
- क्या recursion बेहतर है? खुद मापें कि
SEGFAULT कहाँ आता है और stack depth कितनी है
- exceptions से बचना क्यों ज़रूरी है?
std::error_code या std::variant जैसे alternatives आज़माएँ
- multicore scaling कैसे करें? OpenMP, Intel oneTBB, या खुद बनाए गए thread pool का उपयोग कैसे करें
- memory allocation के बिना JSON को कैसे process करें? क्या C++20 बेहतर है, या पुराना C99 toolset ज़्यादा सरल है?
- STL associative containers को सही तरह इस्तेमाल करने के लिए custom keys और transparent comparators का उपयोग कैसे करें
- अगर hand-written parser से तेज तरीका हो तो?
consteval आधारित regular expression engine के साथ सीधी टक्कर
- क्या pointer size सच में 64-bit है? pointer tagging का उपयोग करके देखें
- UDP कितने packets drop करता है? user space में
io_uring के साथ web requests तक प्रोसेस करके देखें
- Scatter-Gather के साथ 50% तेज vectorized non-contiguous memory operations लागू करना
- Intel oneAPI vs Nvidia CCCL?
<thrust> और <cub> में क्या खास है?
- CUDA C++, PTX, SASS CPU code से कैसे अलग हैं?
- अगर code performance-sensitive है? intrinsics, inline
asm, या .S files में से किसे चुनना चाहिए, इसकी तुलना
- Tensor Core और memory architecture — CPU, Volta, Ampere, Hopper, Blackwell GPUs में क्या अंतर है?
- FPGA coding, GPU से कैसे अलग है? high-level synthesis (HLS), Verilog, VHDL में क्या अंतर है? 🔜 #36
- Encrypted Enclave क्या है? Intel SGX, AMD SEV, ARM Realm की latency तुलना 🔜 #31
चलाने का तरीका और environment setup
- Linux + GCC environment recommended, WSL या Mac के Clang (non-default distribution) का भी उपयोग किया जा सकता है
CMake, liburing, OpenBLAS, g++, build-essential install करना आवश्यक
less_slow executable को build करके चलाने पर benchmarks अपने आप execute हो जाते हैं
git clone https://github.com/ashvardanian/less_slow.cpp.git
cd less_slow.cpp
pip install cmake --upgrade
sudo apt install -y build-essential g++ liburing-dev libopenblas-base
cmake -B build_release -D CMAKE_BUILD_TYPE=Release
cmake --build build_release --config Release
build_release/less_slow
- CUDA और Intel TBB का उपयोग करना है या नहीं, यह चुना जा सकता है (
-D USE_INTEL_TBB=OFF जैसे flags का उपयोग)
- रनटाइम पर केवल खास benchmarks चुनकर चलाना, JSON में save करना, या output format तय करना संभव है
build_release/less_slow --benchmark_filter=std_sort
build_release/less_slow --benchmark_out=results.json --benchmark_format=json
performance measurement बेहतर करने के tips
- noise कम करने के लिए SMT disable करें और random interleaving का उपयोग करें
- Google Benchmark के
--benchmark_perf_counters option से hardware performance counters मापे जा सकते हैं
sudo build_release/less_slow --benchmark_perf_counters="CYCLES,INSTRUCTIONS"
- या Linux के
perf tool से benchmark measurement किया जा सकता है
sudo perf stat taskset 0xEFFFEFFFEFFFEFFFEFFFEFFFEFFFEFFF build_release/less_slow --benchmark_filter=super_sort
प्रोजेक्ट फ़ाइल संरचना
- मुख्य source:
less_slow.cpp (मुख्यतः CPU benchmark code)
- platform-specific optimization files शामिल: x86/ARM के लिए ASM, CUDA
.cu, PTX .ptx code शामिल
├── less_slow.cpp # मुख्य benchmark code
├── less_slow_amd64.S # x86 assembly
├── less_slow_aarch64.S # ARM assembly
├── less_slow.cu # CUDA C++
├── less_slow_sm70.ptx # PTX IR (Volta)
├── less_slow_sm90a.ptx # PTX IR (Hopper)
external libraries का उपयोग
- Google Benchmark: performance measurement
- Intel oneTBB: parallel STL backend
- Meta libunifex: asynchronous execution model
- range-v3:
std::ranges replacement
- fmt:
std::format replacement
- StringZilla:
std::string replacement
- CTRE:
std::regex replacement
- nlohmann/json, yyjson: JSON parsers
- Abseil: high-performance containers
- cppcoro: coroutine implementation
- liburing: Linux kernel-bypass I/O
- ASIO: asynchronous networking
- Nvidia CCCL, CUTLASS: GPU algorithms और matrix operations
Google Benchmark उपयोग के tips का सार
BENCHMARK() से benchmark register करें, ->Args({x,y}) से parameters पास करें
DoNotOptimize(), ClobberMemory() से compiler optimization नियंत्रित करें
->Iterations(n), ->MinTime(n) से iteration count और benchmark time नियंत्रित करें
->Complexity(...), ->SetComplexityN(n) से time complexity निर्दिष्ट करें
state.PauseTiming(), ResumeTiming() से timing sections को सीधे नियंत्रित करें
state.counters[...] से custom counters register किए जा सकते हैं
memes और humor elements
- शैक्षणिक सामग्री में technical meme images जोड़कर रुचि बढ़ाई गई है
- performance बनाम abstraction, IEEE 754 floating point आदि को हास्यपूर्ण ढंग से प्रस्तुत किया गया है
1 टिप्पणियां
Hacker News राय
40 गुना तेज़ trigonometry:
std::sinजैसे standard library functions को 3 लाइन कोड से तेज़ किया जा सकता हैsin(x)का approximation किया जा सकता हैmicrocontroller पर अनुभव साझा
Abseil के चयन पर राय
performance के लिए C++ में होने वाली विकृतियों पर आलोचना
FPGA और GPU coding के अंतर, साथ ही high-level synthesis, Verilog, VHDL पर अनुरोध
denormalized floating-point numbers के बारे में नई जानकारी
Google Benchmark पोस्ट पर सकारात्मक प्रतिक्रिया
"कम धीमा C, C++, assembly code" से अपेक्षाएँ