Skip to content

Instantly share code, notes, and snippets.

@mdouze
Created March 22, 2017 09:49
Show Gist options
  • Save mdouze/9694e8ec06a8d71add0630ce4e0ea294 to your computer and use it in GitHub Desktop.
Save mdouze/9694e8ec06a8d71add0630ce4e0ea294 to your computer and use it in GitHub Desktop.
Exact search perf with OpenBLAS.
In [1]: import numpy as np
In [2]: import faiss
Failed to load GPU Faiss: No module named swigfaiss_gpu
Faiss falling back to CPU-only.
In [3]: import time
In [4]:
In [4]: # d = 160
In [5]: d = 128
In [6]: X = np.random.random((1000000, d)).astype('float32')
In [7]:
In [7]: index = faiss.IndexFlatL2(d)
In [8]:
In [8]: index.add(X)
In [9]:
In [9]: t0 = time.time(); index.search(X[:19], 20); print time.time() - t0
0.0915608406067
In [10]:
In [10]: t0 = time.time(); index.search(X[:20], 20); print time.time() - t0
0.513067960739
In [11]: t0 = time.time(); index.search(X[:20], 20); print time.time() - t0
2.2951130867
In [12]: t0 = time.time(); index.search(X[:20], 20); print time.time() - t0
0.477697849274
In [13]: t0 = time.time(); index.search(X[:20], 20); print time.time() - t0
5.21513700485
In [14]: faiss.omp_set_num_threads(1)
In [15]: t0 = time.time(); index.search(X[:20], 20); print time.time() - t0
0.331252098083
In [16]: t0 = time.time(); index.search(X[:20], 20); print time.time() - t0
0.32853102684
In [17]: t0 = time.time(); index.search(X[:20], 20); print time.time() - t0
0.333997964859
In [18]: faiss.omp_set_num_threads(20)
In [19]: t0 = time.time(); index.search(X[:20], 20); print time.time() - t0
0.46444106102
In [20]: t0 = time.time(); index.search(X[:20], 20); print time.time() - t0
0.452957868576
In [21]: t0 = time.time(); index.search(X[:20], 20); print time.time() - t0
0.461181879044
In [22]: faiss.omp_set_num_threads(40)
In [23]: t0 = time.time(); index.search(X[:20], 20); print time.time() - t0
5.00787210464
In [24]: t0 = time.time(); index.search(X[:20], 20); print time.time() - t0
4.98109602928
In [25]: t0 = time.time(); index.search(X[:20], 20); print time.time() - t0
4.99316191673
In [26]: faiss.omp_set_num_threads(20)
In [27]: t0 = time.time(); index.search(X[:20], 20); print time.time() - t0
0.458247900009
In [28]: t0 = time.time(); index.search(X[:20], 20); print time.time() - t0
0.453998088837
In [29]: faiss.omp_set_num_threads(1)
In [30]: t0 = time.time(); index.search(X[:20], 20); print time.time() - t0
0.315454006195
In [31]: t0 = time.time(); index.search(X[:20], 20); print time.time() - t0
0.342401027679
In [32]: t0 = time.time(); index.search(X[:20], 20); print time.time() - t0
0.32044506073
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment