DEV Community

Cover image for I Benchmarked My Custom Language on a $150 Phone. 1 Core Beat 8 Cores. Here’s Why.
Harun - solo dev for HYNAWEB

Posted on Edited on

I Benchmarked My Custom Language on a $150 Phone. 1 Core Beat 8 Cores. Here’s Why.

Good morning? No. God morning. 👑

I just finished the v2.5.0-pre benchmark stress test for my custom programming language, H-code. I ran it on my POCO C55 (MediaTek Helio G85, 8 cores, 4GB RAM) entirely inside Termux.

I expected to see my 8-thread parallel implementation crush the single-threaded version.

I was wrong. The results completely broke my understanding of how this hardware works. Here is the raw data, the tables, and the brutal truths the silicon told me.

🧱 1. The Android Walled Garden (GPU is a Lie)

My phone has an ARM Mali-G52 MC2 GPU. I wanted to use it for parallel compute. I wrote a C probe to dlopen the OpenCL drivers. The file exists on the filesystem, but Android threw a BLOCKED error.

Here is the exact probe output:

Path Result
/vendor/lib64/libOpenCL.so fail
/system/lib64/libOpenCL.so fail
/system/vendor/lib64/libOpenCL.so fail
/vendor/lib64/egl/libGLES_mali.so fail
libOpenCL.so fail

The truth: Since Android 7, the OS uses strict linker namespaces. Unprivileged apps (like Termux) are physically blocked from loading vendor libraries. The GPU is sitting right there, completely unused.

🐛 2. The Compiler Caught Its Own Lie

Before benchmarking, I ran the standard library verification. Look at this table:

Function Expected Observed Status
dot(a, b, n) 70 70 Pass
vec_sum(a, n) 10 10 Pass
vec_mean(a, n) 2.5 2 Truncation
vec_max(b, n) 8 8 Pass
vec_mag2(a, n) 30 30 Pass

vec_mean([1, 2, 3, 4]) returned 2. The actual mean is 2.5. Why did my language lie? Because H-code currently only supports Int[] arrays. The standard library was performing integer division and silently truncating the decimal. I caught my own language failing at basic math.

⚔️ 3. The Main Event: 1 Optimized Core vs 8 Threads

I wrote a dot-product kernel and ran it in two modes: Sequential (1 thread) and Parallel (8 POSIX threads).

First, I compiled with -O0 (no optimizations). The 8 threads won, giving a 2.61x speedup at 20M elements. Standard stuff.

Then, I compiled with -O2. Look at the raw timings:

n = 20,000,000 elements

Configuration Time Speedup
-O0 Sequential 149.02 ms 1.00x
-O0 Parallel ×8 57.10 ms 2.61x
-O2 Sequential 20.38 ms 7.31x
-O2 Parallel ×8 18.06 ms 8.24x

Wait. At -O2, the 8 threads only gave a 1.13x speedup over the sequential version.

But look closer: The single-threaded -O2 version (20.38ms) was 2.80x faster than the 8-threaded -O0 version (57.10ms).

The Lesson: Clang’s auto-vectorization was so aggressive that a single optimized core absolutely destroyed eight unoptimized cores. Thread-level parallelism is useless if you aren't leveraging instruction-level parallelism first.

🧬 4. Reading the Matrix (The Assembly Proof)

I didn't just trust the timer. I wanted to know how Clang got that 7.31x speedup at -O2. So I dumped the ARM64 assembly output (clang -S) and grepped for vector instructions. Here is what the compiler actually emitted:

Instruction Semantics
smlal v0.2d, v4.2s, v5.2s Signed Multiply-Accumulate Long. Lower half of source vectors.
smlal2 v1.2d, v4.4s, v5.4s Same operation on the upper half of the 4× int32 source vectors.
addp d0, v0.2d Pairwise addition; horizontal reduction of the int64 accumulator pair.

Clang wasn't just running a loop. It was using NEON SIMD. It was using smlal to process 4 integers at the exact same time, and it unrolled the loop 4 ways to hide latency.

📉 5. The Memory Bandwidth Ceiling

At -O2 with 20 million elements, we hit the physical limit of the RAM. You cannot read data from DRAM faster than the physical wires allow.

Configuration Throughput Derived Bandwidth
-O0 sequential 134.2 M MAC/s 1.07 GB/s
-O0 parallel ×8 350.3 M MAC/s 2.80 GB/s
-O2 sequential 981.4 M MAC/s 7.85 GB/s
-O2 parallel ×8 1.107 G MAC/s 8.86 GB/s

The parallel version only pushed 1.13x more bandwidth because we maxed out the memory controller. Adding more cores at this point just creates a traffic jam.

🌡️ 6. The DVFS Trap (How the Phone Lied to Me)

In my very first run, the 8-thread parallel version was actually slower than the sequential version.

Run Sequential Parallel Speedup
1 (cold process) 11.54 ms 12.87 ms 0.90x
2 (warm process) 11.57 ms 4.92 ms 2.35x

The code didn't change. The compiler didn't change. What changed? The phone woke up.

Android uses DVFS (Dynamic Voltage and Frequency Scaling). In the first run, the CPU cores were asleep at a low clock speed. The overhead of spawning 8 threads took longer than the actual math. By the second run, the CPU was "warm" and clocked up to 2.0 GHz. If you don't account for CPU frequency scaling, your benchmarks are meaningless.

🛠️ What’s Next for H-Code?

This benchmark broke a lot of things, and that’s exactly what it was supposed to do.

  1. I need to implement Float[] arrays so vec_mean doesn't truncate.
  2. I need to build a persistent thread pool so we don't pay the spawn cost on every function call.
  3. I need to add an adaptive threshold so the language automatically falls back to sequential for small arrays.

H-code v2.5.0-pre isn't just a language update. It's a proof that you can do serious, silicon-level systems engineering on a $150 Android phone.

GitHub: https://github.com/harun-sket/H-code.git
NPM: https://www.npmjs.com/package/hcode-lang

If you want to see the full raw data, the assembly dumps, and the exact C code I used to trap the DVFS governor, check the repo.

Let's keep pushing the limits. 🐯☁️🚀

Top comments (5)

Collapse
 
akhourianmolkumar profile image
Akhouri Anmol Kumar •

may I know why you mention always your mobile in posts? like now most of dev knows your struggle so better not to mention it repetedly in fact lol 8 cores you literally gave inch to inch specs of it hehe
I also sometimes mention 1 laptop in my post but sometimes
and you: from linkedin to dev everywhere your mobile mobile 150dollar and more.

Collapse
 
koda2026 profile image
Harun - solo dev HYNAWEB •

Bro this is a benchmark article so we must say the platform for devs lol

Collapse
 
akhourianmolkumar profile image
Akhouri Anmol Kumar •

bro in 99% of your post you mention mobile 150 dollar bruh bro I respect your struggle and honestly if someone said me to manage akhouri systems from mobile only for 1 week I will struggle a lot and you are running company for lifetime till now with mobile all respect towards you but bro mentioning mobile in everypost sounds weird you know right? better to keep it as a advise from Co-Founder @ Hynaweb and as a BRO too.

Thread Thread
 
koda2026 profile image
Harun - solo dev HYNAWEB •

Okay co founder

Collapse
 
koda2026 profile image
Harun - solo dev HYNAWEB •