【发布时间】:2021-04-15 06:35:45
【问题描述】:
我在 excel (VBA) 和 python 之间运行了一个小测试,执行一个简单的循环。下面列出的代码。令我惊讶的是,vba 比 python 快得多。快了将近 6 倍。我认为由于 python 通过命令行运行,性能会更好。你们有这方面的cmet吗?
Python
import time
import ctypes # An included library with Python install.
start_time = time.time()
for x in range(0, 1000000):
print x
x = ("--- %s seconds ---" % (time.time() - start_time))
ctypes.windll.user32.MessageBoxA(0, x, "Your title", 1)
Excel (VBA)
Sub looptest()
Dim MyTimer As Double
MyTimer = Timer
Dim rng As Range, cell As Range
Set rng = Range("A1:A1000000")
x = 1
For Each cell In rng
cell.Value = x
x = x + 1
Next cell
MsgBox Timer - MyTimer
End Sub
【问题讨论】: