Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overcomplicating things? #13

Open
kbigliar opened this issue Jan 16, 2019 · 2 comments
Open

Overcomplicating things? #13

kbigliar opened this issue Jan 16, 2019 · 2 comments

Comments

@kbigliar
Copy link
Contributor

TwitchBot/bot.py

Lines 207 to 227 in 28e2a8d

# Get current Day Month Year
currentDate = datetime.datetime.utcnow().strftime("%Y-%m-%d")
m = re.search('(.+?)-', currentDate)
currentYear = m.group(1).encode('ascii', 'ignore')
m = re.search('-(.+?)-', currentDate)
currentMonth = m.group(1).encode('ascii', 'ignore')
m = re.search('-(.*)', currentDate)
currentDay = m.group(1).encode('ascii', 'ignore')
m = re.search('-(.*)', currentDay)
currentDay = m.group(1).encode('ascii', 'ignore')
# Get current Hour Minute Second
currentTime = datetime.datetime.utcnow().strftime("%H:%M:%S")
m = re.search('(.+?):', currentTime)
currentHour = m.group(1).encode('ascii', 'ignore')
m = re.search(':(.+?):', currentTime)
currentMinute = m.group(1).encode('ascii', 'ignore')
m = re.search(':(.*)', currentTime)
currentSecond = m.group(1).encode('ascii', 'ignore')
m = re.search(':(.*)', currentSecond)
currentSecond = m.group(1).encode('ascii', 'ignore')

and

TwitchBot/bot.py

Lines 234 to 237 in 28e2a8d

currentDate = datetime.date(int(currentYear), int(currentMonth), int(currentDay))
currentDateTime = datetime.datetime.combine(currentDate,
datetime.time(int(currentHour), int(currentMinute), int(currentDay),
0, tzinfo=None))

Why not use currentDateTime = datetime.datetime.now() ?

@kbigliar
Copy link
Contributor Author

Better yet, declare currentDateTime outside the for loop on line 182.

@kbigliar
Copy link
Contributor Author

Timing code seen here: https://repl.it/repls/BetterWideCopyright
Destructing and rebuilding a datetime runs on average about 4 times as slow as just using a datetime.datetime.now().
Additionally, as you don't care for the microsecond differences in the time, building the datetime for each follower currently increases the overhead about a thousandfold and linearly takes longer the more followers you get.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant