Optimize the benchmark script
This commit is contained in:
parent
8e278d9c25
commit
e9a08e27a3
|
|
@ -0,0 +1,13 @@
|
||||||
|
/**
|
||||||
|
* Ip2region lua c binding
|
||||||
|
*
|
||||||
|
* @author chenxin<chenxin619315@gmail.com>
|
||||||
|
* @date 2018/10/04
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <lua.h>
|
||||||
|
#include <lualib.h>
|
||||||
|
#include <luaxlib.h>
|
||||||
|
#include "../c/ip2region.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -6,11 +6,11 @@
|
||||||
" Date : 2018-10-04
|
" Date : 2018-10-04
|
||||||
"""
|
"""
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time, sys
|
||||||
|
|
||||||
from ip2Region import Ip2Region
|
from ip2Region import Ip2Region
|
||||||
|
|
||||||
class BeachmarkThread(threading.Thread):
|
class BenchmarkThread(threading.Thread):
|
||||||
__searcher = None
|
__searcher = None
|
||||||
__lock = None
|
__lock = None
|
||||||
|
|
||||||
|
|
@ -25,17 +25,22 @@ class BeachmarkThread(threading.Thread):
|
||||||
sTime = time.time() * 1000
|
sTime = time.time() * 1000
|
||||||
data = self.__searcher.memorySearch("49.220.138.233")
|
data = self.__searcher.memorySearch("49.220.138.233")
|
||||||
eTime = time.time() * 1000
|
eTime = time.time() * 1000
|
||||||
|
# @Note uncomment the print to make it more like the product environment
|
||||||
print("%s|%s in %5f millseconds" % (data["city_id"], data["region"].decode('utf-8'), eTime - sTime))
|
print("%s|%s in %5f millseconds" % (data["city_id"], data["region"].decode('utf-8'), eTime - sTime))
|
||||||
finally:
|
finally:
|
||||||
self.__lock.release()
|
self.__lock.release()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
dbFile = "./data/ip2region.db"
|
||||||
|
if ( len(sys.argv) > 2 ):
|
||||||
|
dbFile = sys.argv[1];
|
||||||
|
|
||||||
threads = []
|
threads = []
|
||||||
searcher = Ip2Region("/data/ip2region/data/ip2region.db")
|
searcher = Ip2Region(dbFile)
|
||||||
lock = threading.Lock()
|
lock = threading.Lock()
|
||||||
|
|
||||||
for i in range(10000):
|
for i in range(10000):
|
||||||
t = BeachmarkThread(searcher, lock)
|
t = BenchmarkThread(searcher, lock)
|
||||||
threads.append(t)
|
threads.append(t)
|
||||||
|
|
||||||
sTime = time.time() * 1000
|
sTime = time.time() * 1000
|
||||||
|
|
@ -46,4 +51,4 @@ if __name__ == "__main__":
|
||||||
t.join()
|
t.join()
|
||||||
eTime = time.time() * 1000
|
eTime = time.time() * 1000
|
||||||
|
|
||||||
print("Beachmark done: %5f" % (eTime - sTime))
|
print("Benchmark done: %5f" % (eTime - sTime))
|
||||||
Loading…
Reference in New Issue