search
HomeTechnology peripheralsAIThis compiler can make Python as fast as C++: up to a hundred times faster, produced by MIT

Since the rise of deep learning, Python has been one of the hottest programming languages. It dominates the fields of data science and machine learning, and even plays a starring role in scientific and mathematical computing. . Nowadays, you can find a corresponding Python package for almost any project you can imagine.

However, while the simplified syntax of a high-level language makes it easy to learn and use, it is slower than a low-level language like C or C.

Researchers at the MIT Computer Science and Artificial Intelligence Laboratory (CSAIL) hope to change that with Codon, a Python-based compiler that allows users Write Python code that runs as efficiently as C or C programs, while being customizable and adaptable to different needs and environments.

The latest paper of this research, "Codon: A Compiler for High-Performance Pythonic Applications and DSLs", was published at the 32nd ACM SIGPLAN International Conference on Compiler Construction in February.

This compiler can make Python as fast as C++: up to a hundred times faster, produced by MIT

  • ## Project link: https://github.com/exaloop/codon
  • Paper: https://dl.acm.org/doi/abs/10.1145/3578360.3580275
##In development work , people need to use a compiler to convert source code into machine code that can be executed by a computer processor. Codon can help developers create new domain-specific languages ​​(DSLs) in Python while still getting the performance advantages of other languages.

"Regular Python is compiled into so-called bytecode, which is executed in a virtual machine, which makes it much slower," said Codon, the lead author of the paper Ariya Shajii said, "With Codon, we compile natively, so you can run the final result directly on the CPU - without going through an intermediate virtual machine or interpreter."

This compiler can make Python as fast as C++: up to a hundred times faster, produced by MIT

Codon's compilation pipeline includes type checking, allowing it to run Python code more efficiently.

The Python-based compiler comes with pre-built binaries for Linux and macOS, and you can also build or generate executables from source. "With Codon, you can distribute source code like Python, or you can compile it into binaries," Shajii said. "If you want to distribute a binary, it will be the same as a language like C, such as a Linux binary or a Mac binary."

To make Codon faster, research People decided to perform type checking at compile time. Type checking involves assigning a data type (such as integer, string, character, or float, etc.) to a value. For example, the number 5 can be assigned as an integer, the letter c can be assigned as a character, the word hello can be assigned as a string, and the decimal number 3.14 can be assigned as a floating point number.

"In regular Python, all types are given to the runtime," Shajii said. "Using Codon, we do type checking during compilation, which allows us to avoid all expensive type manipulation at runtime."

Saman Amarasinghe, principal researcher at MIT CSAIL, added, " If you have a dynamic language (like Python), every time you have some data, you need to keep a lot of extra metadata around it to determine the type of runtime. Codon does away with this metadata, so the code is faster Faster and smaller data size."

According to Shajii, Codon does not have any unnecessary data or type checking at runtime, so there is zero overhead. In terms of performance, "Codon is generally on par with C. We typically see 10x to 100x speed improvements compared to Python."

On the other hand, Codon The approach has its trade-offs. "We do this static type checking and don't allow the use of some of Python's dynamic features, such as dynamically changing types at runtime," Shajii said.

"There are still some Python libraries that we haven't implemented yet." Amarasinghe added, "Python has been actually tested by countless people, and Codon has not reached that level yet. It needs to run more programs to obtain More feedback, and more reinforcement. It will take some time to reach a stable level of regular Python."

Codon was originally designed for genomics and bioinformatics work. The researchers tried about 10 common genomics applications written in Python and compiled them using Codon, achieving speedups of 5 to 10 times compared to the original manually optimized implementation.

"Data sets in these fields have become very large today, and high-level languages ​​like Python and R are too slow to handle the terabytes of data per sequencing set," Shajii said. "That's the gap we want to fill - by building a way to process big data without having to write C or C code to help domain experts who are not computer science or professional developers."

This compiler can make Python as fast as C++: up to a hundred times faster, produced by MIT

The above chart compares the performance of Python (CPython 3), PyPy, Codon, and C on several benchmarks. The y-axis shows the speedup of the Codon implementation relative to the CPython implementation. MIT/EXALOOP/UNIVERSITY OF VICTORIA/ACM

In addition to genomics, Codon can also be applied to similar applications that handle massive data sets, as well as Python-based compilation GPU programming and parallel programming supported by the processor. In fact, Codon is now being used commercially in bioinformatics, deep learning, and quantitative finance through the startup Exaloop, which Shajii founded to transform Codon from an academic project into an industry application.

To enable Codon to adapt to different fields, the team developed a plug-in system. "It's like an extensible compiler," Shajii said. "You can write plug-ins for genomics or other fields, and these plug-ins can have new libraries and new compiler optimizations."

In addition, companies and institutions can use Codon to prototype and develop your own applications. "One of the patterns we see is that people use Python for prototyping and testing because it's easy to use, but when it comes to something important, they have to rewrite the application or have someone else do it in C or C Rewrite and test on a larger data set," Shajii said. "With Codon, you can fully use Python and get the best of both worlds."

Regarding the future of Codon, Shajii and his team are currently working on native versions of the widely used Python library. implementation, as well as library-specific optimizations to help people get better performance from these libraries. They also plan to create a popular feature: Codon's WebAssembly backend to support running code on a web browser.

The above is the detailed content of This compiler can make Python as fast as C++: up to a hundred times faster, produced by MIT. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:51CTO.COM. If there is any infringement, please contact admin@php.cn delete
An easy-to-understand explanation of how to set up two-step authentication in ChatGPT!An easy-to-understand explanation of how to set up two-step authentication in ChatGPT!May 12, 2025 pm 05:37 PM

ChatGPT Security Enhanced: Two-Stage Authentication (2FA) Configuration Guide Two-factor authentication (2FA) is required as a security measure for online platforms. This article will explain in an easy-to-understand manner the 2FA setup procedure and its importance in ChatGPT. This is a guide for those who want to use ChatGPT safely. Click here for OpenAI's latest AI agent, OpenAI Deep Research ⬇️ [ChatGPT] What is OpenAI Deep Research? A thorough explanation of how to use it and the fee structure! table of contents ChatG

[For businesses] ChatGPT training | A thorough introduction to 8 free training options, subsidies, and examples![For businesses] ChatGPT training | A thorough introduction to 8 free training options, subsidies, and examples!May 12, 2025 pm 05:35 PM

The use of generated AI is attracting attention as the key to improving business efficiency and creating new businesses. In particular, OpenAI's ChatGPT has been adopted by many companies due to its versatility and accuracy. However, the shortage of personnel who can effectively utilize ChatGPT is a major challenge in implementing it. In this article, we will explain the necessity and effectiveness of "ChatGPT training" to ensure successful use of ChatGPT in companies. We will introduce a wide range of topics, from the basics of ChatGPT to business use, specific training programs, and how to choose them. ChatGPT training improves employee skills

A thorough explanation of how to use ChatGPT to streamline your Twitter operations!A thorough explanation of how to use ChatGPT to streamline your Twitter operations!May 12, 2025 pm 05:34 PM

Improved efficiency and quality in social media operations are essential. Particularly on platforms where real-time is important, such as Twitter, requires continuous delivery of timely and engaging content. In this article, we will explain how to operate Twitter using ChatGPT from OpenAI, an AI with advanced natural language processing capabilities. By using ChatGPT, you can not only improve your real-time response capabilities and improve the efficiency of content creation, but you can also develop marketing strategies that are in line with trends. Furthermore, precautions for use

[For Mac] Explaining how to get started and how to use the ChatGPT desktop app![For Mac] Explaining how to get started and how to use the ChatGPT desktop app!May 12, 2025 pm 05:33 PM

ChatGPT Mac desktop app thorough guide: from installation to audio functions Finally, ChatGPT's desktop app for Mac is now available! In this article, we will thoroughly explain everything from installation methods to useful features and future update information. Use the functions unique to desktop apps, such as shortcut keys, image recognition, and voice modes, to dramatically improve your business efficiency! Installing the ChatGPT Mac version of the desktop app Access from a browser: First, access ChatGPT in your browser.

What is the character limit for ChatGPT? Explanation of how to avoid it and upper limits by modelWhat is the character limit for ChatGPT? Explanation of how to avoid it and upper limits by modelMay 12, 2025 pm 05:32 PM

When using ChatGPT, have you ever had experiences such as, "The output stopped halfway through" or "Even though I specified the number of characters, it didn't output properly"? This model is very groundbreaking and not only allows for natural conversations, but also allows for email creation, summary papers, and even generate creative sentences such as novels. However, one of the weaknesses of ChatGPT is that if the text is too long, input and output will not work properly. OpenAI's latest AI agent, "OpenAI Deep Research"

What is ChatGPT's voice input and voice conversation function? Explaining how to set it up and how to use itWhat is ChatGPT's voice input and voice conversation function? Explaining how to set it up and how to use itMay 12, 2025 pm 05:27 PM

ChatGPT is an innovative AI chatbot developed by OpenAI. It not only has text input, but also features voice input and voice conversation functions, allowing for more natural communication. In this article, we will explain how to set up and use the voice input and voice conversation functions of ChatGPT. Even when you can't take your hands off, ChatGPT responds and responds with audio just by talking to you, which brings great benefits in a variety of situations, such as busy business situations and English conversation practice. A detailed explanation of how to set up the smartphone app and PC, as well as how to use each.

An easy-to-understand explanation of how to use ChatGPT for job hunting and job hunting!An easy-to-understand explanation of how to use ChatGPT for job hunting and job hunting!May 12, 2025 pm 05:26 PM

The shortcut to success! Effective job change strategies using ChatGPT In today's intensifying job change market, effective information gathering and thorough preparation are key to success. Advanced language models like ChatGPT are powerful weapons for job seekers. In this article, we will explain how to effectively utilize ChatGPT to improve your job hunting efficiency, from self-analysis to application documents and interview preparation. Save time and learn techniques to showcase your strengths to the fullest, and help you make your job search a success. table of contents Examples of job hunting using ChatGPT Efficiency in self-analysis: Chat

An easy-to-understand explanation of how to create and output mind maps using ChatGPT!An easy-to-understand explanation of how to create and output mind maps using ChatGPT!May 12, 2025 pm 05:22 PM

Mind maps are useful tools for organizing information and coming up with ideas, but creating them can take time. Using ChatGPT can greatly streamline this process. This article will explain in detail how to easily create mind maps using ChatGPT. Furthermore, through actual examples of creation, we will introduce how to use mind maps on various themes. Learn how to effectively organize and visualize your ideas and information using ChatGPT. OpenAI's latest AI agent, OpenA

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version