why so much differnt performance in python 2.7.10, 2.7.14 and 3.6.4 - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: General (https://python-forum.io/forum-1.html) +--- Forum: News and Discussions (https://python-forum.io/forum-31.html) +--- Thread: why so much differnt performance in python 2.7.10, 2.7.14 and 3.6.4 (/thread-8198.html) |
why so much differnt performance in python 2.7.10, 2.7.14 and 3.6.4 - jiangtianyong - Feb-09-2018 Hi ALL I have a question when i develop a testcase to run in different python version 1: Python 2.7.10 (default, Feb 7 2017, 00:08:15) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin (here is python) 2: Python 2.7.14 (default, Jan 6 2018, 12:15:00) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin (here is python2 in my env) 3:Python 3.6.4 (v3.6.4:d48ecebad5, Dec 18 2017, 21:07:28) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin (here is my python3) the same code run on the three different python version, i take much different time Here is the code: #!/usr/bin/env python #coding:utf-8 ''' test GIL global interpreter lock ''' from threading import Thread import time from multiprocessing import Process from multiprocessing import Pool import multiprocessing def counter(): i = 0 for _ in range(50000000): i += 1 return True def multiprocessPool_main(): start = time.time() pool = Pool(processes=4) for x in range(10): pool.apply_async(counter, args=()) pool.close() pool.join() end = time.time() print('in pool processes take %s seconds' % (end - start)) def multiprocess_main(): start = time.time() p1 = Process(target=counter, args=()) p2 = Process(target=counter, args=()) p3 = Process(target=counter, args=()) p1.start() p2.start() p3.start() print("The number of CPU is:" + str(multiprocessing.cpu_count())) for p in multiprocessing.active_children(): print("child p.name: " + p.name + "\tp.id: " + str(p.pid)) p1.join() p2.join() p3.join() end = time.time() print('3 processes take %s seconds' % (end - start)) def main(): start_time = time.time() for tid in range(2): t = Thread(target=counter) t.start() t.join() end_time = time.time() print ("total time of single is: {}".format(end_time - start_time)) def multi_main(): thread_all = [] start_time = time.time() for tid in range(2): t = Thread(target=counter) t.start() thread_all.append(t) for i in range(2): thread_all[i].join() end_time = time.time() print ("total time of multi is: {}".format(end_time -start_time)) if __name__ == '__main__': main() multi_main() multiprocess_main() multiprocessPool_main()
output in python 3.6.4 output in python 2.7.10 output in the python 2.7.14
|