Papers
Topics
Authors
Recent
Search
2000 character limit reached

Behind Python: The Languages That Power AI

Published 16 Jun 2026 in cs.PL | (2606.18141v1)

Abstract: Python dominates AI development, yet the numerical work behind frameworks like PyTorch and NumPy is executed in C, C++, or Rust. When a developer must implement an algorithm without such libraries -- because none exists, the target is resource-constrained, or a new system is being built -- which language should they choose? This paper answers that question empirically. Five algorithms covering data mining (k-means), machine learning (k-NN), neural networks (MLP with backpropagation), computational intelligence (genetic algorithm), and fuzzy systems (Mamdani inference) are implemented from scratch in Python, C, C++, Rust, Go, and Julia. All implementations share a common pseudo-random generator, consume identical inputs, and produce bit-identical outputs, so every measured difference reflects the language rather than the computation. Three performance tiers emerge: C and C++ are effectively tied; Rust trails them by 9% (geometric mean); Julia runs 3.3x slower than C and Go 5.0x; Python sits at 315x. Memory tells a different story -- Julia's JIT runtime carries a fixed ~224 MiB footprint regardless of workload, while C, C++, and Rust stay below 6 MiB. Crucially, rankings are not stable: Go's slowdown swings from 2.6x on k-NN to 8.0x on k-means, showing that workload characteristics can shift a language's position by a full tier. The results provide concrete, per-workload guidance for choosing an implementation language in AI systems.

Summary

  • The paper systematically benchmarks six programming languages for AI using from-scratch implementations of five canonical algorithms.
  • It reveals that C, C++, and Rust dominate in execution speed and memory efficiency, while Python lags and Julia shows fixed high memory usage.
  • The study’s rigorous methodology provides actionable insights for selecting programming languages in resource-constrained AI system deployments.

Empirical Analysis of Programming Languages for AI Algorithm Implementation

Introduction

This study, "Behind Python: The Languages That Power AI" (2606.18141), conducts a systematic, empirical benchmarking of six major programming languages—Python, C, C++, Rust, Go, and Julia—using from-scratch implementations of five canonical AI algorithms: kk-means clustering, kk-nearest neighbors (k-NN), a multilayer perceptron (MLP), a genetic algorithm (GA), and a Mamdani fuzzy inference system. By excluding third-party libraries and enforcing deterministic execution, the investigation isolates the impact of language, runtime, and compiler features on execution speed, memory usage, binary size, development effort, and compilation latency. The cross-language evaluation provides granular insights directly relevant to system builders and researchers who must select an implementation substrate when developing new AI algorithms, targeting resource-constrained environments, or extending the AI software stack beyond the reach of established libraries.

Experimental Methodology

To ensure comparability, each implementation in the six languages adheres to strict algorithmic equivalence with controlled sources of randomness and minimal reliance on language-specific idioms. All tests execute on the same hardware (Apple M1 Pro, macOS), with optimization flags set for maximal native performance where applicable. Benchmarks are sized such that C and C++ executions complete in 0.35–0.75 s, making timer noise negligible yet permitting all languages (even Python) to run the suite within reasonable wall-clock time.

A single, reproducible 64-bit LCG pseudo-random generator is implemented verbatim across all languages, ensuring bit-identical input streams. Floating-point computations are limited to IEEE-754 basic arithmetic operations to avoid discrepancies from transcendental library variations. Two output fingerprints per task (integer and floating-point) are validated for cross-language agreement, confirming the computational equivalence of the implementations.

Results

Execution Time

Three clear performance tiers emerge (Figure 1). C and C++ are statistically indistinguishable, setting the performance floor; Rust trails by an average of 9% (geometric mean). Julia and Go comprise a transitional tier, at 3.3×3.3\times and 5.0×5.0\times the speed of C, respectively. Python is, on average, 315×\times slower than C, with all benchmarks confirming its position as an outlier for raw execution speed. Figure 1

Figure 1: Mean wall-clock time per benchmark illustrates the near-superposition of C, C++, and Rust; Julia and Go are intermediate; Python is orders of magnitude slower (logarithmic scale).

Crucially, Julia generally outperforms Go except on one task, challenging the common expectation that JIT-compiled languages are always slower than statically compiled ones. Notably, Go’s slowdown relative to C varies substantially by workload—ranging from 2.6×\times on k-NN to 8.0×\times on k-means—demonstrating that algorithmic characteristics can induce rank fluctuations even within the same language.

Memory Consumption

Memory usage is sharply stratified (Figure 2). Systems languages (C, C++, Rust) exhibit peak resident set sizes consistently under 6 MiB. Go’s garbage collector increases memory usage to $6$–$8$ MiB, while Python’s interpreter pushes usage to roughly $28$ MiB. Julia is a clear outlier, with a JIT runtime footprint of ~224 MiB that remains essentially invariant to the workload. This fixed cost can be prohibitive on memory-constrained deployments, overshadowing by two orders of magnitude the minimal memory consumption of the systems-languages tier. Figure 2

Figure 2: Julia's mean peak resident set size (kk0224 MiB) dwarfs that of all other languages, remaining constant across benchmarks (logarithmic scale).

Holistic Language Profiles

Comparisons of five metrics (execution time, memory use, binary size, lines of code, compile time) reveal that no language is Pareto-optimal across all axes (Figure 3). C and C++ closely overlap and dominate in runtime metrics; Python and Julia regain ground only on code conciseness (when isolating from-scratch code, without libraries). Rust’s binaries are larger and compilation slower—reflecting its optimization pipeline—yet performance is near-identical to C/C++, with additional memory safety guarantees. Go’s binaries are the largest and code the most verbose, reflecting its managed runtime and explicit error-handling conventions. Figure 3

Figure 3: Five-metric radar chart shows the tight grouping of C/C++ and their dominance on runtime and memory; managed and JIT languages recover only on developer-cost (conciseness) axes.

Discussion

Time–Memory–Productivity Trade-offs

Strong claims substantiated by experimental evidence:

  • Python confers no code conciseness advantage in from-scratch, library-free AI algorithm implementations relative to C or C++.
  • Julia achieves higher execution speed than Go on most tasks, but with a fixed memory overhead likely to be unacceptable in resource-limited scenarios.
  • Rust's performance is consistently close to C/C++, supporting adoption in safety-critical infrastructure without meaningful runtime penalties.

The lack of code-size advantage in Python highlights that its productivity reputation is contingent on leveraging optimized libraries (NumPy, PyTorch, etc.), and not on the expressiveness or succinctness of the language for low-level algorithmic development per se.

Workload Sensitivity

Language rankings are not invariant across AI workloads. Go’s relative rank fluctuates by more than a factor of three due to differing hot-path characteristics (indexing, floating-point intensity, branch predictability). Julia’s JIT compilation excels on branch-heavy, less arithmetic-bound tasks (e.g., the GA benchmark), while lagging behind as floating-point arithmetic density increases.

Practical and Theoretical Implications

From a systems design standpoint, C, C++, and Rust remain the default choices for AI foundation-layer implementations where maximal runtime performance and minimal footprint are required. Julia can be effective for rapid prototyping or in environments where memory is abundant and JIT overhead is tolerated, but cannot be the default choice for embedded or constrained-edge scenarios. Go remains relevant for cloud-native and distributed AI services where memory overheads are modest and developer tooling is prioritized. Python is fundamentally dependent on native acceleration and unsuitable for new, performance-critical kernels in isolation.

These findings imply that system architects and AI tooling developers must prioritize workload analysis when making language choices, as the optimal candidate varies with computation pattern and deployment context. Moreover, bridging the gap between research and production performance for new algorithms may require the introduction of these kernels into inner-loop native languages before library-level binding.

Speculation and Future Directions

Extending this methodology to include:

  • Modern deep learning primitives, e.g., transformer kernels and GPU-backed workloads, could further differentiate language tiers.
  • SIMD, GPU, and library-bound optimizations, which were out of scope here, would likely accentuate the need for C/C++/Rust backends under Python/Julia/Go interfaces in practical systems.
  • Cross-architecture comparisons (e.g., x86-64, ARM64, specialized AI accelerators) are needed to fully understand how much these findings generalize beyond Apple silicon and macOS.

The findings underscore the continued relevance of systems-programming languages at the base of the AI stack and suggest that efforts to improve productivity and safety (e.g., adoption of Rust in infrastructure projects) are not fundamentally at odds with realized performance.

Conclusion

The controlled study establishes that, when stripped of library crutches, Python’s productivity and performance vanish, and C/C++/Rust dominate for bare-metal AI algorithm implementation. Julia and Go interpolate between ease-of-use and runtime cost, but with workload-dependent unpredictability and memory trade-offs. Selection of programming language for new AI infrastructure must consider the detailed computational characteristics of its target algorithms and deployment context. The study's rigorous methodology offers a blueprint for future benchmarking at the intersection of programming languages and AI systems research.

Paper to Video (Beta)

No one has generated a video about this paper yet.

Whiteboard

No one has generated a whiteboard explanation for this paper yet.

Open Problems

We haven't generated a list of open problems mentioned in this paper yet.

Collections

Sign up for free to add this paper to one or more collections.

HackerNews