我打开一个16mb的简单txt文件,以使用mplotlib显示图形。在IDLE中运行python文件需要7秒才能显示图表。在VS Code中,需要17秒。文件大小为55mb时,分别需要17秒和53秒。
为什么VS Code变慢,我如何获得与IDLE相似的速度?
代码:
import numpy as np
import matplotlib.pyplot as plt
import time as time
time, v_out, v_in = np.loadtxt('PS_SIM.txt', unpack=True, skiprows=1)
plt.plot(time, v_out, label="Vout")
#Set legends
plt.legend(loc=8)
plt.grid()
plt.xlabel("Time [s]")
plt.ylabel("V_out [V]")
plt.suptitle("V_out")
#Set scales
plt.ylim(0.95, 1.05)
plt.yticks(np.arange(0.95,1.05, step=0.01))
plt.xlim(0.0085, 0.010)
#Show plot
plt.show()
settings.json:
{
"python.pythonPath": "C:\\Users\\<..>\\AppData\\Local\\Programs\\Python\\Python36-32\\python.exe"
}
task.json:
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "msbuild",
"args": [
// Ask msbuild to generate full paths for file names.
"/property:GenerateFullPaths=true",
"/t:build"
],
"group": "build",
"presentation": {
// Reveal the output only if unrecognized errors occur.
"reveal": "silent"
},
// Use the standard MS compiler pattern to detect errors, warnings and infos
"problemMatcher": "$msCompile"
}
]
launch.json:
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File (Integrated Terminal)",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
},
...
答案 0 :(得分:0)
Idle和VS Code在执行代码时可能使用不同的Python解释器。当您从像VS Code这样的IDE中运行Python程序时,它将使用您在该IDE设置中指定的解释器。我猜Idle使用的是标准Python解释器,因为它实际上不是IDE