Virgin Functional Algorithm vs Chad Solution
Virgin Functional "Algorithm" Everyone understands him in 5 minutes Compiles to dozens of wasteful instructions Melts your CPU with AVX fn calculate(bottom: i32, top: i32) -> i32 { (bottom..=top) .filter(|e| e % 2 == 0) .sum() } World's most advanced compiler cannot make him fast. Allegedly "unreadable garbage" Never takes the same amount of time Takes multiple seconds to answer calculate(0, 1000000000) Chad Closed-form Solution Over a BILLION times faster Not even the original author understands him. int calculate_best(int bottom, int top) { bottom = (bottom + 1) & ~1; top = (top - bottom + 1) >> 1; return top * (top + bottom + 1) + bottom; } Definitely unreadable Always takes the same amount of time Compiles to just 8 instructions Extremely fast even on a 4004 Completes in NANOSECONDS
A split comparison shows a nervous Virgin character using a readable functional algorithm that filters and sums even numbers, contrasted with a muscular Chad using an opaque closed-form formula. The joke is that the unreadable mathematical shortcut is vastly faster, even on an ancient Intel 4004 processor, while the understandable code is slow and inefficient. It is used as a reaction to praise clever optimization over readability. EN: A split comparison shows a nervous Virgin character using a readable functional algorithm that filters and sums even numbers, contrasted with a muscular Chad using an opaque closed-form formula. The joke is that the unreadable mathematical shortcut is vastly faster, even on an ancient Intel 4004 processor, while the understandable code is slow and inefficient. It is used as a reaction to praise clever optimization over readability.
- @gentoomemes / 14065 2024-10-15
- Template
- Virgin vs. Chad
- Type
- image
- Size
- 800×400 · 69.8 KiB
- Mood
- sarcastic, absurd
- Language
- en
- Added