arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2606.18141cs.PL
收藏

Python 背后:驱动人工智能的语言

Behind Python: The Languages That Power AI

Tecnológico de Monterrey(蒙特雷科技大学)

Juan P. Licona-Luque, Beatriz A. Bosques-Palomo, Nezih Nieto-Gutiérrez, Gustavo de los Ríos-Alatorre, Luis A. Muñoz-Ubando

AI总结:

通过五种AI算法的从头实现,实证比较Python、C、C++、Rust、Go和Julia的性能,发现C/C++最快,Rust慢9%,Julia慢3.3倍,Python慢315倍,且排名因工作负载而异。

摘要:

Python 主导了人工智能开发,但 PyTorch 和 NumPy 等框架背后的数值计算工作是由 C、C++ 或 Rust 执行的。当开发者必须在不使用此类库的情况下实现算法时——因为不存在这样的库、目标资源受限或正在构建新系统——他们应该选择哪种语言?本文通过实证回答了这个问题。五种算法涵盖了数据挖掘(k-means)、机器学习(k-NN)、神经网络(带反向传播的 MLP)、计算智能(遗传算法)和模糊系统(Mamdani 推理),它们分别用 Python、C、C++、Rust、Go 和 Julia 从头实现。所有实现共享相同的伪随机生成器,消耗相同的输入,并产生比特相同的输出,因此每个测量到的差异反映的是语言而非计算。出现了三个性能层级:C 和 C++ 几乎持平;Rust 落后它们 9%(几何平均);Julia 比 C 慢 3.3 倍,Go 慢 5.0 倍;Python 慢 315 倍。内存方面则不同——Julia 的 JIT 运行时无论工作负载如何都带有约 224 MiB 的固定占用,而 C、C++ 和 Rust 保持在 6 MiB 以下。关键在于,排名并不稳定:Go 的减速幅度从 k-NN 的 2.6 倍到 k-means 的 8.0 倍不等,表明工作负载特征可以将语言的位置移动整整一个层级。这些结果为在 AI 系统中选择实现语言提供了具体的、按工作负载的指导。

英文摘要:

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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑