- Notifications
You must be signed in to change notification settings - Fork1k
Open
Description
hi.
so i know that you probably know this
but if there will be a 3rd edition, exapmles 19-13 and 19-12 (and other examples in chapter 19) need a rework.
e.g the mentioned examples actually fail to prove the point of multiprocessing being good for cpu bound work since the prime number example is done in less than a second
the perf_countr() actually shows0.00
and 19-13 actually takes longer due to multiprocessing overhead
below is the result of running them on python 3.12.2 on a not very new xeon cpu withperf_counter()
python sequential.py Checking 20 numbers sequentially: 2 P 0.000001s 142702110479723 P 0.000002s 299593572317531 P 0.000001s3333333333333301 P 0.000001s3333333333333333 P 0.000001s3333335652092209 P 0.000001s4444444444444423 P 0.000001s4444444444444444 0.000001s4444444488888889 P 0.000001s5555553133149889 P 0.000001s5555555555555503 P 0.000001s5555555555555555 P 0.000001s6666666666666666 0.000001s6666666666666719 P 0.000001s6666667141414921 P 0.000001s7777777536340681 P 0.000001s7777777777777753 P 0.000001s7777777777777777 P 0.000001s9999999999999917 P 0.000001s9999999999999999 P 0.000001sTotal time: 0.00s
python procs.py Cheking 20 numbers with 16 processes: 2 P 0.000035s 142702110479723 P 0.000003s 299593572317531 P 0.000002s3333333333333301 P 0.000001s3333333333333333 P 0.000001s3333335652092209 P 0.000001s4444444444444423 P 0.000001s4444444444444444 0.000001s4444444488888889 P 0.000001s5555555555555503 P 0.000001s5555555555555555 P 0.000001s6666666666666666 0.000001s6666666666666719 P 0.000001s6666667141414921 P 0.000001s7777777536340681 P 0.000001s7777777777777753 P 0.000001s7777777777777777 P 0.000001s9999999999999917 P 0.000001s9999999999999999 P 0.000001s5555553133149889 P 0.000033s20 checks in 0.02s
and this is the result usingperf_counter_ns()
python sequential.py Checking 20 numbers sequentially: 2 P 487.000000ns 142702110479723 P 1047.000000ns 299593572317531 P 500.000000ns3333333333333301 P 320.000000ns3333333333333333 P 295.000000ns3333335652092209 P 279.000000ns4444444444444423 P 214.000000ns4444444444444444 296.000000ns4444444488888889 P 215.000000ns5555553133149889 P 200.000000ns5555555555555503 P 222.000000ns5555555555555555 P 247.000000ns6666666666666666 290.000000ns6666666666666719 P 196.000000ns6666667141414921 P 227.000000ns7777777536340681 P 202.000000ns7777777777777753 P 202.000000ns7777777777777777 P 202.000000ns9999999999999917 P 202.000000ns9999999999999999 P 202.000000nsTotal time: 118353.00ns
python procs.py Cheking 20 numbers with 16 processes: 2 P 13804.000000ns 142702110479723 P 2860.000000ns 299593572317531 P 1762.000000ns3333333333333301 P 1324.000000ns3333333333333333 P 1270.000000ns3333335652092209 P 1073.000000ns4444444444444423 P 794.000000ns4444444444444444 1200.000000ns4444444488888889 P 810.000000ns5555553133149889 P 890.000000ns5555555555555503 P 753.000000ns5555555555555555 P 995.000000ns6666666666666666 925.000000ns6666666666666719 P 813.000000ns6666667141414921 P 678.000000ns7777777536340681 P 763.000000ns7777777777777753 P 703.000000ns9999999999999917 P 941.000000ns9999999999999999 P 740.000000ns7777777777777777 P 26330.000000ns20 checks in 18213477.00ns
Metadata
Metadata
Assignees
Labels
No labels