Код: Выделить всё
for input_line in sys.stdin:
line_lst = input_line.split('\t')
if '"text-1' in line_lst[5]:
write_text_1(line_lst[1], line_lst[3], line_lst[2], line_lst[5])
elif '"text-2":' in line_lst[5]:
write_text_2(line_lst[1], line_lst[3], line_lst[2], line_lst[5])
elif '"other-text' in line_lst[5]:
write_other_text(line_lst[1], line_lst[3], line_lst[2], line_lst[5])
elif 'string-5' in line_lst[5]:
write_string_5(line_lst[1], line_lst[3], line_lst[2], line_lst[5])
Я запустил сценарий через cProfile, и задержки, похоже, находятся в пределах сравнения строк:
Код: Выделить всё
4482211 23.477 0.000 221.176 0.000 queues.py:369(put)
4482211 25.623 0.000 110.693 0.000 connection.py:181(send_bytes)
4482211 25.838 0.000 34.225 0.000 reduction.py:38(__init__)
4482211 43.656 0.000 43.656 0.000 {built-in method posix.write}
4482214 2.652 0.000 2.652 0.000 {method 'copy' of 'dict' objects}
4482232 5.735 0.000 5.735 0.000 {method 'update' of 'dict' objects}
8903380 3.625 0.000 3.625 0.000 {method 'end' of 're.Match' objects}
8903496 12.774 0.000 12.774 0.000 {method 'match' of 're.Pattern' objects}
Есть ли более быстрый способ сравнения нескольких разных строк, чем структура if/elif?>
Подробнее здесь: https://stackoverflow.com/questions/798 ... omparisons
Мобильная версия