performance.py 983 B

12345678910111213141516171819202122232425262728293031323334353637
  1. """
  2. Test the performance of the search in terms of compression and speed.
  3. """
  4. import os
  5. from datetime import datetime
  6. from itertools import islice
  7. from spacy.lang.en import English
  8. from index import Indexer, index_titles_and_urls
  9. from paths import TEST_INDEX_PATH
  10. from wiki import get_wiki_titles_and_urls
  11. def performance_test():
  12. nlp = English()
  13. try:
  14. os.remove(TEST_INDEX_PATH)
  15. except FileNotFoundError:
  16. print("No test index found, creating")
  17. indexer = Indexer(TEST_INDEX_PATH)
  18. titles_and_urls = get_wiki_titles_and_urls()
  19. titles_and_urls_slice = islice(titles_and_urls, 1000)
  20. start_time = datetime.now()
  21. index_titles_and_urls(indexer, nlp, titles_and_urls_slice)
  22. stop_time = datetime.now()
  23. index_time = (stop_time - start_time).total_seconds()
  24. index_size = os.path.getsize(TEST_INDEX_PATH)
  25. print("Index time:", index_time)
  26. print("Index size", index_size)
  27. if __name__ == '__main__':
  28. performance_test()