Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os, datetime as dt
- ADD_BENCHMARK_TO_LOG_FILE = True
- def GetMessageContent():
- result = ''
- with open("message.txt") as file:
- result = file.read()
- return result
- map = {
- '\\' : "\\\\", '`' : "\\`",
- '*' : "\\*", '_' : "\\_"
- }
- content = GetMessageContent()
- t1 = dt.datetime.now()
- result = []
- for c in content:
- dictResult = map.get(c, None)
- if dictResult != None:
- result.append(dictResult)
- else:
- result.append(c)
- resultStr = ''.join(result)
- t2 = dt.datetime.now()
- print(f'That took {(t2 - t1).microseconds * 1000} nanoseconds.\n')
- if ADD_BENCHMARK_TO_LOG_FILE:
- with open("log.txt", "a") as file:
- file.write(f'Python: {(t2 - t1).microseconds * 1000} nanoseconds.\n')
- if input("See resulting text? Y or N?\n").upper() == 'Y':
- print(resultStr)
Advertisement
Add Comment
Please, Sign In to add comment