0
使用python-> curses模块时,如果我拼凑字符串颜色属性,我会遇到非常缓慢的 绘制/刷新。 我用C++编写了相同的程序,并没有问题。 代码:Python诅咒,缓慢刷新不同的连续颜色
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import curses
import locale
# Inint global console config
locale.setlocale(locale.LC_ALL, '')
def main(stdscr):
curses.start_color()
curses.use_default_colors()
curses.init_pair(1, curses.COLOR_YELLOW, 0)
curses.init_pair(2, curses.COLOR_RED, 0)
max_rows, max_cols = stdscr.getmaxyx()
max_cont = max_rows * max_cols
try:
for i in range(1, max_cont):
stdscr.addstr('█', curses.color_pair(i % 2 + 1))
except curses.ERR:
pass
stdscr.refresh()
stdscr.getch()
curses.wrapper(main)
但是为什么用C++编写的代码非常快?即使我改变'█'的字符,例如'A'仍然很慢。 –
Python是一个解释器,比C++中的编译器应用程序有更多的工作要做。 –
我不认为发送的数据量是问题,因为正如我所说的,只有在颜色交替时才会变慢。如果我仅使用一种颜色对,发送的数据量是相同的,但它工作速度非常快。 –