我用来在 C 中定义宏(不仅仅是常量)
I use to define macros (not just constants) in C like
#define loop(i,a,b) for(i=a; i<b; ++i)
#define long_f(a,b,c) (a*0.123 + a*b*5.6 - 0.235*c + 7.23*c - 5*a*a + 1.5)
有没有办法在 python 中使用 preprocess 而不是函数?
Is there a way of doing this in python using a preprocess instead of a function?
*通过 preprocess 我的意思是在运行代码之前替换定义的出现(实际上不是整个代码而是其余代码,因为它是代码的一部分,我猜它将在运行时替换所有内容).
*By preprocess I mean something that replaces the occurrences of the definition before running the code (actually not the whole code but the rest of the code, because since it's part of the code, I guess it will replace everything during runtime).
如果有,值得吗?运行时间会有显着差异吗?
If there is, worth it? Will there be a significant difference in run time?
好吧,如果您要执行一些可以提前执行的非常困难的计算,那么,也许这是有道理的:通常用户会更开心使用快程序而不是慢程序.
Well, if you're going to perform some really hard calculations that could be performed in advance, then, perhaps, this makes sense: usually users are more happy with fast programs rather than slow ones.
但是,就原始性能"(即算术计算的速度)而言,恐怕 python 不是一个好的选择.至少如果我们谈论标准的 Python 实现,称为 CPython.
But, I'm afraid python isn't a good choice when it comes to 'raw performance', that is, speed of arithmetic calculations. At least if we talk about the standard python implementation, called CPython.
或者,您可以检查其他变体:
Alternatively, you could check other variants:
这篇关于相当于 Python 的 C 预处理器宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!