Open jooossshhhh opened 1 year ago
@jooossshhhh Makes sense! I think that was the original architecture - https://github.com/teacherc/spheri-app/commit/2bc7329acd84560bf234b6c5dd0d3dbafa590552#diff-b10564ab7d2c520cdd0243874879fb0a782862c3c902ab535faabe57d5a505e1
@jooossshhhh Do you think there is an even better way to assign the genre? It's possible it might be faster with a hashmap.
Yes, that's one way I can see to make it faster. Personally, I don't see the need to change to that because of speed alone. I timed the aforementioned function and it clocked in at 1.6 ms, so probably not something to worry too much about. I think for now, since there aren't many if statements, readability isn't a problem either. Switching to elif statements and ending with else made the function faster by .5 ms. I'd say that's a significant time difference without changing the structure entirely.
@jooossshhhh Ah, I was talking about space/time complexity. Link: https://www.youtube.com/watch?v=D6xkbGLQesk
This can't be measured by either of us checking how much time it takes to load a page (that load time is influenced by many things including our Internet connections).
I think these if-statements don't really need to be changed for time or space complexity (the complexity is constant). One reason to change them would be to make it a bit more Pythonic. Sometimes, I also try to put the conditions that are most-likely to occur first (I think doing that here would make it less readable). Also, if this app was a bit more complex, I would actually take that logic out of the main.py file and put it another place.
I wasn't timing the time it took to load the page, I wrote a function to time how long it took the assign_genre function to run in isolation. If we're talking about time complexity, yes it would be constant in this case. Finally, I do think something like a hashmap would make the code more Pythonic if that's what you're going for.
In assign_genre function, most of the ifs should be elif to make the evaluation a bit faster. Maybe the last if in the chain could be an else statement to cover more ground. See here for more context.