Home>


Search for a character string that has [Name, Furigana, Score] as a set and search for a character string that matches the name or furigana.
I want to speed up the process as much as possible. (It takes time to search because there are tens of thousands of directory data)

What I did
①Store the name list in the 2D array of the list and search from the beginning → It took time
② Search the database by executing the SQL statement every time after putting the list in the database → It is faster than ① but still takes time

Because I don't have much knowledge about python, I'd like to know what speedups can be considered. (You can use this library, do this, etc.)

Thank you m (_ _) m

for name in names:
            if name == meibo ["name"] or name == meibo ["furigana"]:
                print (meibo ["score"])
  • Answer # 1

    Whether it should be sorted and binary search, or put it all in a hash table (dictionary). Basically, the latter should be faster.

    However, whether it's a sorted array search or a hash table, it seems that it will take some time to make it first (although some tens of thousands may have been seen), I made it Dump things with pickle, etc., and make a program that reads them afterwards.

  • Answer # 2

    When tuning, first measure where the time is spent in the profiler (cProfile).
    Reference: Python profiler

    If SQL, pasteINDEXto thenameandphoneticof the table, and set theWHEREcondition to 1 Whether it should be in the form to acquire the matter.

    c.execute ('SELECT * FROM meibo WHERE name =? OR furigana =?', (name, token.base_form,))