Python Forum
Need to speed up my code.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need to speed up my code.
#3
The performance issues seem reasonably obvious: you're doing a count (which one would assume is O(n)) on each iteration and you're also doing a remove each iteration (which is also O(n)). So, you're doing O(n^2) operations, given that map will also be O(n). You can at least figure out the most common in a single pass over the array (it is left as an exercise to figure out exactly how!) and then do the summing after that.
Reply


Messages In This Thread
Need to speed up my code. - by blackknite - Jan-14-2020, 05:04 PM
RE: Need to speed up my code. - by Gribouillis - Jan-14-2020, 06:49 PM
RE: Need to speed up my code. - by ndc85430 - Jan-15-2020, 08:36 AM
RE: Need to speed up my code. - by blackknite - Jan-19-2020, 01:24 AM
RE: Need to speed up my code. - by perfringo - Jan-19-2020, 07:57 AM
RE: Need to speed up my code. - by jefsummers - Jan-19-2020, 02:02 PM
RE: Need to speed up my code. - by perfringo - Jan-20-2020, 08:24 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020