Python 3.6.6 |Anaconda custom (64-bit)| (default, Jun 28 2018, 17:14:51)

Type "copyright", "credits" or "license" for more information.


IPython 6.5.0 -- An enhanced Interactive Python.


In [1]: import random


In [2]: random.seed(0)


In [3]: L = random.sample(range(-10000, 10000), 1000000)

Traceback (most recent call last):


File "<ipython-input-3-22463d750f36>", line 1, in <module>

L = random.sample(range(-10000, 10000), 1000000)


File "/opt/anaconda3/lib/python3.6/random.py", line 320, in sample

raise ValueError("Sample larger than population or is negative")


ValueError: Sample larger than population or is negative



In [4]:


In [4]: L = random.sample(range(-10000000, 10000000), 1000000)


In [5]: len(L)

Out[5]: 1000000


In [6]: random.randint(1,6)

Out[6]: 3


In [7]: random.randint(1,6)

Out[7]: 2


In [8]: random.randint(1,6)

Out[8]: 5


In [9]: random.randint(1,6)

Out[9]: 5


In [10]: random.randint(1,6)

Out[10]: 6


In [11]: random.randint(1,6)

Out[11]: 4


In [12]: random.randint(1,6)

Out[12]: 2


In [13]: import lezione5


In [14]: lezione5.k_massimi(L, 3)

Out[14]: [9999951, 9999922, 9999902]


In [15]: %time lezione5.k_massimi(L, 3)

CPU times: user 102 ms, sys: 0 ns, total: 102 ms

Wall time: 102 ms

Out[15]: [9999896, 9999869, 9999775]


In [16]: %time lezione5.k_massimi(L, 3)

CPU times: user 93 ms, sys: 0 ns, total: 93 ms

Wall time: 93 ms

Out[16]: [9999742, 9999714, 9999705]


In [17]: %timeit lezione5.k_massimi(L, 3)

95.7 ms ± 1.27 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)


In [18]: import lezione5


In [19]: %time lezione5.k_massimi2(L, 3)

CPU times: user 740 ms, sys: 4.91 ms, total: 745 ms

Wall time: 745 ms

Out[19]: [9994975, 9994877, 9994719]


In [20]: import math


In [21]: math.log2(1000000)

Out[21]: 19.931568569324174


In [22]: %time lezione5.k_massimi2(L, 300)

CPU times: user 739 ms, sys: 950 µs, total: 740 ms

Wall time: 741 ms

Out[22]:

[9994975,

9994877,

9994719,

9994713,

9994689,

9994658,

9994558,

9994475,

9994460,

9994459,

9994442,

9994422,

9994405,

9994399,

9994358,

9994339,

9994336,

9994334,

9994298,

9994282,

9994281,

9994267,

9994223,

9994218,

9994213,

9994176,

9994166,

9994151,

9994097,

9994085,

9994081,

9994078,

9994019,

9994017,

9994001,

9993989,

9993942,

9993940,

9993931,

9993917,

9993885,

9993847,

9993831,

9993779,

9993775,

9993753,

9993729,

9993720,

9993658,

9993654,

9993633,

9993618,

9993616,

9993605,

9993570,

9993562,

9993541,

9993533,

9993495,

9993492,

9993472,

9993448,

9993419,

9993312,

9993298,

9993281,

9993269,

9993268,

9993239,

9993215,

9993212,

9993165,

9993088,

9993007,

9992994,

9992971,

9992941,

9992939,

9992927,

9992919,

9992906,

9992897,

9992841,

9992830,

9992789,

9992785,

9992760,

9992724,

9992680,

9992670,

9992647,

9992628,

9992623,

9992619,

9992578,

9992575,

9992572,

9992571,

9992507,

9992489,

9992449,

9992447,

9992368,

9992362,

9992349,

9992335,

9992332,

9992330,

9992323,

9992299,

9992288,

9992282,

9992257,

9992247,

9992224,

9992210,

9992199,

9992195,

9992179,

9992163,

9992154,

9992127,

9992123,

9992116,

9992080,

9992079,

9992060,

9992052,

9992048,

9992038,

9992022,

9992021,

9991991,

9991929,

9991919,

9991913,

9991888,

9991870,

9991824,

9991809,

9991797,

9991775,

9991744,

9991740,

9991691,

9991679,

9991678,

9991659,

9991625,

9991595,

9991568,

9991547,

9991489,

9991482,

9991472,

9991457,

9991445,

9991441,

9991430,

9991417,

9991408,

9991364,

9991362,

9991355,

9991349,

9991337,

9991319,

9991303,

9991291,

9991275,

9991271,

9991256,

9991246,

9991207,

9991196,

9991174,

9991169,

9991164,

9991146,

9991145,

9991143,

9991089,

9991087,

9991042,

9991023,

9991007,

9990989,

9990983,

9990962,

9990943,

9990895,

9990879,

9990878,

9990870,

9990852,

9990850,

9990828,

9990796,

9990768,

9990699,

9990666,

9990615,

9990608,

9990598,

9990595,

9990578,

9990577,

9990563,

9990555,

9990536,

9990528,

9990524,

9990496,

9990469,

9990460,

9990454,

9990439,

9990434,

9990410,

9990399,

9990372,

9990370,

9990367,

9990361,

9990342,

9990341,

9990287,

9990276,

9990252,

9990246,

9990241,

9990217,

9990215,

9990197,

9990176,

9990146,

9990110,

9990107,

9990075,

9990050,

9990049,

9990042,

9990032,

9990003,

9989991,

9989958,

9989947,

9989940,

9989920,

9989878,

9989866,

9989865,

9989854,

9989845,

9989839,

9989832,

9989790,

9989763,

9989745,

9989735,

9989720,

9989697,

9989647,

9989629,

9989594,

9989591,

9989578,

9989479,

9989438,

9989427,

9989410,

9989400,

9989399,

9989388,

9989362,

9989321,

9989319,

9989280,

9989193,

9989160,

9989159,

9989157,

9989152,

9989145,

9989112,

9989096,

9989062,

9989043,

9989010,

9988958,

9988948,

9988925,

9988898,

9988880,

9988861,

9988859,

9988857,

9988846,

9988840,

9988766]


In [23]: %time massimi = lezione5.k_massimi2(L, 300)

CPU times: user 758 ms, sys: 960 µs, total: 759 ms

Wall time: 760 ms


In [24]: %time massimi = lezione5.k_massimi(L, 300)

CPU times: user 9.56 s, sys: 595 µs, total: 9.56 s

Wall time: 9.58 s


In [25]: import lezione5


In [26]: lezione5.k_massimi3(1000000, 3)

Out[26]: [9999940, 9999940, 9999961]


In [27]: %time lezione5.k_massimi3(1000000, 3)

CPU times: user 1.76 s, sys: 940 µs, total: 1.76 s

Wall time: 1.76 s

Out[27]: [9999979, 9999974, 9999971]


In [28]: random.seed(0)


In [29]: %time lezione5.k_massimi3(1000000, 3)

CPU times: user 1.8 s, sys: 0 ns, total: 1.8 s

Wall time: 1.81 s

Out[29]: [9999902, 9999951, 9999922]


In [30]: random.seed(0)


In [31]: %time lezione5.k_massimi3(1000000, 3)

CPU times: user 1.86 s, sys: 944 µs, total: 1.86 s

Wall time: 1.87 s

Out[31]: [9999902, 9999951, 9999922]


In [32]: %time lezione5.k_massimi3(1000000, 300)

CPU times: user 7.51 s, sys: 0 ns, total: 7.51 s

Wall time: 7.53 s

Out[32]:

[9998618,

9998827,

9995097,

9997184,

9996660,

9995595,

9997203,

9994558,

9997539,

9996794,

9994773,

9995359,

9997880,

9996932,

9999159,

9999568,

9994180,

9998522,

9997512,

9995462,

9996548,

9997557,

9994391,

9995483,

9996908,

9997566,

9995460,

9995416,

9999407,

9994683,

9997635,

9999061,

9997463,

9995192,

9998450,

9997183,

9996815,

9996513,

9998615,

9996625,

9997709,

9998496,

9997080,

9998543,

9996060,

9996121,

9996214,

9998498,

9994998,

9999127,

9997872,

9998947,

9997149,

9997326,

9999120,

9995159,

9997741,

9998583,

9994477,

9994730,

9994357,

9999613,

9996341,

9994668,

9996525,

9995036,

9996818,

9996042,

9997699,

9999771,

9995819,

9995621,

9996918,

9994906,

9994839,

9999762,

9997004,

9995449,

9995200,

9994168,

9997806,

9997121,

9998746,

9995172,

9999487,

9995201,

9994127,

9996208,

9995934,

9994754,

9998660,

9999195,

9995565,

9997611,

9995160,

9997565,

9995727,

9995586,

9996023,

9999101,

9994224,

9999848,

9996063,

9995942,

9998216,

9996300,

9999078,

9998455,

9998810,

9999380,

9996127,

9998143,

9999940,

9994135,

9996668,

9994447,

9998475,

9994538,

9997930,

9997458,

9998243,

9997452,

9995590,

9996706,

9998223,

9997408,

9999585,

9998404,

9999513,

9997201,

9999718,

9997237,

9999749,

9996593,

9999587,

9995201,

9999557,

9999260,

9999176,

9999800,

9998898,

9998873,

9999750,

9995132,

9998577,

9997184,

9995196,

9999172,

9995187,

9994346,

9996147,

9996522,

9998525,

9994997,

9996515,

9998015,

9997448,

9999305,

9994343,

9996603,

9998731,

9998136,

9996431,

9994126,

9999168,

9999628,

9994649,

9995743,

9997755,

9997022,

9999525,

9998795,

9998140,

9998239,

9994677,

9997588,

9994883,

9998435,

9997543,

9996881,

9995575,

9995574,

9999761,

9996363,

9994385,

9999654,

9999940,

9997016,

9998938,

9995949,

9995421,

9996304,

9999142,

9995180,

9996563,

9995335,

9996312,

9998295,

9996442,

9998142,

9997903,

9997781,

9999043,

9994372,

9996678,

9999072,

9994743,

9994411,

9999149,

9995013,

9998621,

9994825,

9998551,

9999274,

9997964,

9999337,

9999216,

9995556,

9997713,

9996132,

9997287,

9998173,

9996023,

9998139,

9997992,

9999837,

9994375,

9997432,

9998697,

9996647,

9998012,

9999630,

9999961,

9995202,

9999464,

9995824,

9998976,

9996860,

9995130,

9994343,

9996525,

9997880,

9995425,

9999828,

9994735,

9998240,

9995104,

9997449,

9994955,

9994442,

9998130,

9994917,

9996031,

9994437,

9999545,

9996352,

9995336,

9999528,

9998476,

9998830,

9997448,

9999869,

9994616,

9999702,

9999408,

9997567,

9999762,

9996235,

9996768,

9996330,

9998269,

9998655,

9995154,

9996226,

9995398,

9997234,

9997584,

9996466,

9999893,

9999470,

9999512,

9994461,

9995128,

9994928,

9994332,

9994112,

9998300,

9999604,

9998153,

9996764,

9997835,

9996929,

9995927,

9995328,

9997890,

9997400,

9995980,

9997365,

9999935,

9998199]


In [33]: random.seed(0)


In [34]: %time L=lezione5.k_massimi3(1000000, 300)

CPU times: user 7.09 s, sys: 3.89 ms, total: 7.09 s

Wall time: 7.11 s


In [35]: import lezione5


In [36]: %time L=lezione5.k_massimi4(1000000, 300)

CPU times: user 1.67 s, sys: 0 ns, total: 1.67 s

Wall time: 1.68 s


In [37]: %time L=lezione5.k_massimi3(1000000, 300)

CPU times: user 7.04 s, sys: 0 ns, total: 7.04 s

Wall time: 7.05 s


In [38]: %time L=lezione5.k_massimi4(1000000, 300)

CPU times: user 1.67 s, sys: 0 ns, total: 1.67 s

Wall time: 1.67 s


In [39]: