From e9a08e27a3d812a4f6ed29f967f5a23d8394889a Mon Sep 17 00:00:00 2001 From: lionsoul Date: Fri, 5 Oct 2018 09:49:32 +0800 Subject: [PATCH] Optimize the benchmark script --- binding/clua/Ip2region.c | 13 +++++++++++++ binding/python/{beachmark.py => benchmark.py} | 15 ++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 binding/clua/Ip2region.c rename binding/python/{beachmark.py => benchmark.py} (73%) diff --git a/binding/clua/Ip2region.c b/binding/clua/Ip2region.c new file mode 100644 index 0000000..e238b15 --- /dev/null +++ b/binding/clua/Ip2region.c @@ -0,0 +1,13 @@ +/** + * Ip2region lua c binding + * + * @author chenxin + * @date 2018/10/04 +*/ + +#include +#include +#include +#include "../c/ip2region.h" + + diff --git a/binding/python/beachmark.py b/binding/python/benchmark.py similarity index 73% rename from binding/python/beachmark.py rename to binding/python/benchmark.py index 533746f..5da9b78 100644 --- a/binding/python/beachmark.py +++ b/binding/python/benchmark.py @@ -6,11 +6,11 @@ " Date : 2018-10-04 """ import threading -import time +import time, sys from ip2Region import Ip2Region -class BeachmarkThread(threading.Thread): +class BenchmarkThread(threading.Thread): __searcher = None __lock = None @@ -25,17 +25,22 @@ class BeachmarkThread(threading.Thread): sTime = time.time() * 1000 data = self.__searcher.memorySearch("49.220.138.233") 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)) finally: self.__lock.release() if __name__ == "__main__": + dbFile = "./data/ip2region.db" + if ( len(sys.argv) > 2 ): + dbFile = sys.argv[1]; + threads = [] - searcher = Ip2Region("/data/ip2region/data/ip2region.db") + searcher = Ip2Region(dbFile) lock = threading.Lock() for i in range(10000): - t = BeachmarkThread(searcher, lock) + t = BenchmarkThread(searcher, lock) threads.append(t) sTime = time.time() * 1000 @@ -46,4 +51,4 @@ if __name__ == "__main__": t.join() eTime = time.time() * 1000 - print("Beachmark done: %5f" % (eTime - sTime)) + print("Benchmark done: %5f" % (eTime - sTime))