我正在努力更好地理解这种差异.我在网上找到了很多解释,但它们倾向于抽象的差异而不是实际的含义.
我的大部分编程经验都是CPython(动态,解释)和Java(静态,编译).但是,据我所知,还有其他类型的解释和编译语言.除了可执行文件可以从编译语言编写的程序中分发之外,每种类型都有任何优点/缺点吗?通常,我听到有人认为解释性语言可以交互使用,但我相信编译语言也可以有交互式实现,对吗?
python java compiler-construction interpreter programming-languages
为什么Python平均比C/C++慢?我学习了Python作为我的第一个编程语言,但我只是从C开始,我已经觉得我可以看到明显的区别.
我试图找出为什么当我尝试写入 I2C 时,即使我使用 CDLL,Python 中的相同代码的工作速度也比 C 慢 25 倍。下面我将逐步描述我正在做的所有细节。
树莓派版本:Raspberry PI 3 Model B
操作系统:Raspbian Buster Lite 版本:2019 年 7 月
GCC 版本:gcc (Raspbian 8.3.0-6+rpi1) 8.3.0
Python 版本:Python 3.7.3
尽管 I2C,我正在使用的设备是 MCP23017。我所做的就是将 0 和 1 写入引脚 B0。这是我用 C 编写的代码:
// test1.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/i2c-dev.h>
#include <time.h>
int init() {
int fd = open("/dev/i2c-1", O_RDWR);
ioctl(fd, I2C_SLAVE, 0x20);
return fd;
}
void deinit(int fd) {
close(fd);
}
void makewrite(int fd, int v) …Run Code Online (Sandbox Code Playgroud) python ×3
c ×1
c++ ×1
ctypes ×1
gcc ×1
i2c ×1
interpreter ×1
java ×1
performance ×1
raspberry-pi ×1