想知道python的性能。为了检查raspberry pi3的性能,我生成了如下代码。python版本是2.7.9。在
pslibs/psDebug.py文件
import sys
import time
from datetime import datetime
class CliColor :
YELLOW ='\x1b[00;033;033m'
GREEN = '\x1b[00;032;032m'
RED = '\x1b[00;031;031m'
NONE = '\x1b[00m'
class PSDebug :
@staticmethod
def debug(msg, color=CliColor.NONE) :
if color == CliColor.NONE :
print >> sys.stderr, "%s @ %s" % (datetime.now().strftime("%H:%M:%S.%f"), msg)
else :
print >> sys.stderr, "%s%s @ %s%s" % (color, datetime.now().strftime("%H:%M:%S.%f"), msg, CliColor.NONE)
def DBG(arg, color=CliColor.NONE) :
PSDebug.debug(arg, color)
sys.stderr.flush()
在测试.py文件
^{pr2}$第一次,执行时间/测试.py在终点站。它起作用了而且是诽谤/psDebug.pyc生成。在
第二,删除了libps/psDebug.py执行死刑/测试.py“用libps/psDebug.pyc. 在
第三,libps/psDebug.py已恢复。运行'pyinstaller测试.py'并执行'time./test'。在
结果如下。在
real 0m11.946s
user 0m10.130s
sys 0m1.550s
real 0m26.482s
user 0m24.340s
sys 0m1.820s
real 0m20.362s
user 0m18.820s
sys 0m1.010s
以我的观点来看,这些预测似乎以相反的顺序更快。但是script.py文件更快。当我使用strace实用程序调试时,唯一的区别是“stat system call error”。在
第一次,时间/测试.py'
stat64("/work/temp/libps/psDebug.py", {st_mode=S_IFREG|0644, st_size=936, ...}) = 0
stat64("/work/temp/libps/psDebug.py", {st_mode=S_IFREG|0644, st_size=936, ...}) = 0
stat64("/work/temp/libps/psDebug.py", {st_mode=S_IFREG|0644, st_size=936, ...}) = 0
stat64("/work/temp/libps/psDebug.py", {st_mode=S_IFREG|0644, st_size=936, ...}) = 0
stat64("./test.py", {st_mode=S_IFREG|0755, st_size=185, ...}) = 0
stat64("./test.py", {st_mode=S_IFREG|0755, st_size=185, ...}) = 0
getcwd("/work/temp", 1024) = 11
stat64("./test.py", {st_mode=S_IFREG|0755, st_size=185, ...}) = 0
stat64("./test.py", {st_mode=S_IFREG|0755, st_size=185, ...}) = 0
getcwd("/work/temp", 1024) = 11
gettimeofday({1463756954, 935083}, NULL) = 0
stat64("/etc/localtime", {st_mode=S_IFREG|0644, st_size=557, ...}) = 0
write(2, "00:09:14.935083 @ Count : 9999", 30) = 30
write(2, "\n", 1) = 1
第二,时间/测试.py'
stat64("/work/temp/libps/psDebug.py", 0x7e979a40) = -1 ENOENT (No such file or directory)
stat64("/work/temp/libps/psDebug.py", 0x7e979980) = -1 ENOENT (No such file or directory)
stat64("/work/temp/libps/psDebug.py", 0x7e979a40) = -1 ENOENT (No such file or directory)
stat64("/work/temp/libps/psDebug.py", 0x7e979980) = -1 ENOENT (No such file or directory)
stat64("./test.py", {st_mode=S_IFREG|0755, st_size=185, ...}) = 0
stat64("./test.py", {st_mode=S_IFREG|0755, st_size=185, ...}) = 0
getcwd("/work/temp", 1024) = 11
stat64("./test.py", {st_mode=S_IFREG|0755, st_size=185, ...}) = 0
stat64("./test.py", {st_mode=S_IFREG|0755, st_size=185, ...}) = 0
getcwd("/work/temp", 1024) = 11
gettimeofday({1463756850, 285897}, NULL) = 0
stat64("/etc/localtime", {st_mode=S_IFREG|0644, st_size=557, ...}) = 0
write(2, "00:07:30.285897 @ Count : 9999", 30) = 30
write(2, "\n", 1) = 1
第三,“时间/测试”
stat64("libps/psDebug.py", 0x7eac9a10) = -1 ENOENT (No such file or directory)
getcwd("/work/temp/dist/test", 1024) = 21
stat64("libps/psDebug.py", 0x7eac9928) = -1 ENOENT (No such file or directory)
getcwd("/work/temp/dist/test", 1024) = 21
getcwd("/work/temp/dist/test", 1024) = 21
stat64("libps/psDebug.py", 0x7eac9858) = -1 ENOENT (No such file or directory)
stat64("libps/psDebug.py", 0x7eac9a10) = -1 ENOENT (No such file or directory)
getcwd("/work/temp/dist/test", 1024) = 21
stat64("libps/psDebug.py", 0x7eac9928) = -1 ENOENT (No such file or directory)
getcwd("/work/temp/dist/test", 1024) = 21
getcwd("/work/temp/dist/test", 1024) = 21
stat64("libps/psDebug.py", 0x7eac9858) = -1 ENOENT (No such file or directory)
stat64("test.py", 0x7eac9a10) = -1 ENOENT (No such file or directory)
getcwd("/work/temp/dist/test", 1024) = 21
stat64("test.py", 0x7eac9928) = -1 ENOENT (No such file or directory)
getcwd("/work/temp/dist/test", 1024) = 21
stat64("test.py", 0x7eac9cb0) = -1 ENOENT (No such file or directory)
getcwd("/work/temp/dist/test", 1024) = 21
stat64("test.py", 0x7eac9bc8) = -1 ENOENT (No such file or directory)
getcwd("/work/temp/dist/test", 1024) = 21
gettimeofday({1463756115, 1765}, NULL) = 0
stat64("/etc/localtime", {st_mode=S_IFREG|0644, st_size=557, ...}) = 0
write(2, "23:55:15.001765 @ Count : 6912", 30) = 30
write(2, "\n", 1) = 1
请,建议如何提高第二和第三种方法的性能。在
目前没有回答
相关问题 更多 >
编程相关推荐