Loading skill
Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Writing efficient code that handles large data and tight constraints
| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-02 | ✗→✓ | ▲ Improved | 6% | 0% |
| case-18 | ✗→✓ | ▲ Improved | -12% | 0% |
| case-01 | ✓→✓ | = Same ✓ | -16% | 0% |
| case-03 | ✓→✓ | = Same ✓ | -7% | 0% |
| case-04 | ✓→✓ | = Same ✓ | 32% | 0% |
How to write code that won't timeout on large inputs.
Before writing code, ask: how big is the data?
| Data size | Approach | |-----------|----------| | < 1 MB | Load into memory, any approach works | | 1-100 MB | Load into memory, but use efficient algorithms | | 100 MB - 1 GB | Stream/mmap, avoid loading entirely into memory | | > 1 GB | Streaming only, chunk-based processing |
mmap(), Python: mmap.mmap()) — map file into memory, OS handles pagingfread() in C, open(f, 'rb').read(chunk) in Pythonfgets() when you need random accesswrite() for every bytefwrite() or sys.stdout.buffer.write() for binary outputmmap() for large file access-O2 or -O3 for compiler optimizationsmalloc()/free() in tight loops — pre-allocatememcpy() instead of byte-by-byte copyingnumpy for numerical work (100x faster than pure Python loops)collections.Counter, defaultdict — avoid manual countingstruct.unpack() for binary parsingsubprocess.run() > os.system()wc -cOther measured skills in the registry, with their headline benchmark lift.