Python Forum
Computationally efficient recording + searching?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Computationally efficient recording + searching?
#1
I have not yet programmed this, so it will be in pseudo code, but I would like to know if my idea is good or there is a better way to do it. I need the most computationally efficient way to do this.

Let's assume my script does many computations and then appends strings (e.g. [intint<char>,intint<char>,intint<char>] 2 individual ints and an optional char) to a list. Once the list has been completed, it will be put into a bigger list, if it doesn't already exist. Also, a sort will be performed before putting the list into a bigger list.
Note: A set will have on average 3 elements, but can range from 1-15 (made up these numbers, as I don't know the exact math).

Examples of biglist and small list(set#)
biglist[set1, set2, set3, ..., set1000]
set1[31, 53x, 53, 45]
Assume x == 0, currently [x] is 31 from the above example of set1
How I will sort my set:
1- Sort [x][0] from smallest to largest.
2- Sort [x][1] from smallest to largest.
3- If two have the same [x][0] and [x][1], then one will have an extra char "x" in [x][2], so the size will be bigger, so I will sort this to be after the one without "x".
E.g. set1 would become [31, 45, 53, 53x]

How I will search my biglist:
for x in biglist
    if newset[0][0] == biglist[x][0][0]
        foundflag = true
        break

if foundflag == true
    append newset to biglist
^I need more checks to see if the size of the list and/or all its contents match.

New idea:
Should I compress all possible strings upfront to ints? Then search the map for the corresponding int before appending to newset, sorting and searching?
E.g. [31, 31x, 32, 32x, 33, 33x, 41, 41x, 42, 42x, 43, 43x] would become [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
Then, instead of sorting [x][0], [x][1] and the size in case of a possible "x" in [x][2], I simply sort [x], which is an int?
Reply
#2
Since there have been no suggestions, is it already efficient?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  A more efficient code titanif 2 457 Oct-17-2023, 02:07 PM
Last Post: deanhystad
  Cleaning my code to make it more efficient BSDevo 13 1,273 Sep-27-2023, 10:39 PM
Last Post: BSDevo
  Video recording with Raspberry Pi - What´s wrong with my python code? Montezuma1502 3 1,179 Feb-24-2023, 06:14 PM
Last Post: deanhystad
  Making a function more efficient CatorCanulis 9 1,748 Oct-06-2022, 07:47 AM
Last Post: DPaul
Smile How we can prevent screen recording murad_ali 3 1,756 Jul-29-2022, 10:29 AM
Last Post: DeaD_EyE
  How to decrease latency while recording streaming video. unicorn2019 0 1,232 Nov-15-2021, 02:12 PM
Last Post: unicorn2019
  Help with storing temp data for each day then recording min/max in app. trthskr4 3 2,355 Sep-10-2021, 10:51 PM
Last Post: trthskr4
  Split recording with Picamera EvanS1 0 1,880 Jun-19-2021, 12:26 PM
Last Post: EvanS1
  I there a more efficient way of printing ? Capitaine_Flam 7 3,412 Dec-01-2020, 10:37 AM
Last Post: buran
  Using pyaudio to stop recording under certain sound threshold Twanski94 2 6,294 Jun-13-2020, 11:35 AM
Last Post: Twanski94

Forum Jump:

User Panel Messages

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