{"id":1050,"date":"2022-01-24T17:46:09","date_gmt":"2022-01-24T16:46:09","guid":{"rendered":"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/?p=1050"},"modified":"2022-01-25T11:08:00","modified_gmt":"2022-01-25T10:08:00","slug":"evaluation-de-temps-dexecution","status":"publish","type":"post","link":"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/2022\/01\/24\/evaluation-de-temps-dexecution\/","title":{"rendered":"Evaluation de temps d\u2019ex\u00e9cution"},"content":{"rendered":"\n<p class=\"has-text-color has-background\" style=\"background-color:#a6ddff;color:#1ea9ff\">1<strong> &#8211; Cr\u00e9ation de tableaux al\u00e9atoires d\u2019entiers<\/strong><\/p>\n\n\n\n<p><strong>Cr\u00e9ation d\u2019un tableau t de valeurs al\u00e9atoires \u00e0 trier<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"godzilla\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">t=[]\nn=10\nMax=10\nfor i in range(n):\n    t.append(random.randint(0,Max))<\/pre>\n\n\n\n<p><strong>Mesure de la dur\u00e9e d\u2019ex\u00e9cution d\u2019un programme<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"godzilla\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">debut=time.time()\nt=[]\nfor i in range(100000):\n    t.append(random.randint(0,10))\nduree=time.time()-debut\nprint(duree)<\/pre>\n\n\n\n<p>A quoi correspond la variable debut ? Effectuez un test pour justifier la r\u00e9ponse.<\/p>\n\n\n\n<p>La variable debut correspond au moment o\u00f9<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Tracer un nuage de points<\/strong>&nbsp;&nbsp;<\/p>\n\n\n\n<p>Exemple 10 points de la droite d\u2019\u00e9quation y=-2x+10<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"godzilla\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import matplotlib.pyplot as plt\nx=[i for i in range(10)]\ny=[-2*xval+10 for xval in x]\nplt.scatter(x,y)\nplt.show()<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"388\" height=\"258\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-23.png\" alt=\"\" class=\"wp-image-1064\" srcset=\"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-23.png 388w, http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-23-300x199.png 300w\" sizes=\"(max-width: 388px) 100vw, 388px\" \/><\/figure>\n\n\n\n<p><strong>Visualiser la dur\u00e9e de cr\u00e9ation d\u2019un tableau en fonction de sa longueur n<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"godzilla\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import matplotlib.pyplot as plt\nimport time\nimport random\ndef duree_tableau_alea2(n):\n    t=[]\n    debut=time.time()\n    for i in range(n):\n        t.append(random.randint(0,10))\n    duree=time.time()-debut\n    return duree\nx=[i*10**5 for i in range(10)]\ny2=[duree_tableau_alea2(val) for val in x]\nplt.scatter(x,y2)\nplt.show()<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"386\" height=\"257\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-24.png\" alt=\"\" class=\"wp-image-1066\" srcset=\"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-24.png 386w, http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-24-300x200.png 300w\" sizes=\"(max-width: 386px) 100vw, 386px\" \/><\/figure>\n\n\n\n<p><strong>Comparaisons et options pour le trac\u00e9<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"godzilla\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import time\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport random\ndef duree_tableau_alea(n):\n    debut=time.time()\n    t=[random.randint(0,10) for i in range(n)]\n    duree=time.time()-debut\n    return duree\ndef duree_tableau_alea1(n):\n    debut=time.time()\n    t=list(np.random.randint(10,size=n))\n    duree=time.time()-debut\n    return duree\ndef duree_tableau_alea2(n):\n    t=[]\n    debut=time.time()\n    for i in range(n):\n        t.append(random.randint(0,6))\n    duree=time.time()-debut\n    return duree\nx=[(i)*10**5 for i in range(5)]\ny=[duree_tableau_alea(val) for val in x]\ny1=[duree_tableau_alea1(val) for val in x]\ny2=[duree_tableau_alea2(val) for val in x]\nplt.scatter(x,y, color='coral', linestyle='solid', label='liste en compr\u00e9hension')\nplt.scatter(x,y1, color='navy', linestyle='solid', label='tableau numpy')\nplt.scatter(x,y2, color='green', linestyle='solid', label='liste avec append')\nax = plt.gca()\nax.spines['right'].set_color('none')\nax.spines['top'].set_color('none')\nax.xaxis.set_ticks_position('bottom')\nax.spines['bottom'].set_position(('data',0))\nax.yaxis.set_ticks_position('left')\nax.spines['left'].set_position(('data',0))\nplt.title('dur\u00e9e de c\u00e9ation d''un tableau de n valeurs al\u00e9atoires ',color=\"navy\", fontsize=12)\nax = ax.set(xlabel='n ', ylabel='dur\u00e9e (en s)')\nplt.legend(loc='center right');\nplt.show()<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" width=\"412\" height=\"274\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-25.png\" alt=\"\" class=\"wp-image-1068\" srcset=\"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-25.png 412w, http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-25-300x200.png 300w\" sizes=\"(max-width: 412px) 100vw, 412px\" \/><\/figure>\n\n\n\n<p class=\"has-text-color has-background\" style=\"background-color:#1dacff;color:#a8dfff\"><strong>2. Comparaison de tris<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"godzilla\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import time\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport random\ndef tri_insertion(tableau):\n    for i in range(1,len(tableau)):\n        en_cours = tableau[i]\n        j = i\n        #d\u00e9calage des \u00e9l\u00e9ments du tableau }\n        while j&gt;0 and tableau[j-1]&gt;en_cours:\n            tableau[j]=tableau[j-1]\n            j = j-1\n        #on ins\u00e8re l'\u00e9l\u00e9ment \u00e0 sa place\n        tableau[j]=en_cours  \n        \ndef tri_selection(tableau):\n    nb = len(tableau)\n    for en_cours in range(0,nb):    \n        plus_petit = en_cours\n        for j in range(en_cours+1,nb) :\n            if tableau[j] &lt; tableau[plus_petit] :\n                plus_petit = j\n        if min is not en_cours :\n            temp = tableau[en_cours]\n            tableau[en_cours] = tableau[plus_petit]\n            tableau[plus_petit] = temp\ndef duree_tris(n):\n    t1=list(np.random.randint(10,size=n))\n    t2=t1.copy()\n    t3=t1.copy()\n    debut=time.time()\n    tri_selection(t1)\n    duree_selection=time.time()-debut\n    debut=time.time()\n    tri_insertion(t2)\n    duree_insertion=time.time()-debut\n    debut=time.time()\n    t3.sort()\n    duree_sort=time.time()-debut\n    return duree_selection,duree_insertion,duree_sort\nx=[(i)*10**3 for i in range(10)]\ny=[duree_tris(val) for val in x]\ny1=[y[i][0] for i in range(10)]\ny2=[y[i][1] for i in range(10)]\ny3=[y[i][2] for i in range(10)]\nplt.scatter(x,y1, color='navy', linestyle='solid', label='tri selection')\nplt.scatter(x,y2, color='green', linestyle='solid', label='tri insertion')\nplt.scatter(x,y3, color='red', linestyle='solid', label='tri sort')\nax = plt.gca()\nax.spines['right'].set_color('none')\nax.spines['top'].set_color('none')\nax.xaxis.set_ticks_position('bottom')\nax.spines['bottom'].set_position(('data',0))\nax.yaxis.set_ticks_position('left')\nax.spines['left'].set_position(('data',0))\nplt.title('dur\u00e9e pour trier un tableau de n valeurs al\u00e9atoires ',color=\"navy\", fontsize=12)\nax = ax.set(xlabel='n ', ylabel='dur\u00e9e (en ms)')\nplt.legend(loc='upper left');\nplt.show()\nprint(y1)\nprint(y2)\nprint(y2)<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"424\" height=\"281\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-34.png\" alt=\"\" class=\"wp-image-1090\" srcset=\"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-34.png 424w, http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-34-300x199.png 300w\" sizes=\"(max-width: 424px) 100vw, 424px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"880\" height=\"64\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-35.png\" alt=\"\" class=\"wp-image-1091\" srcset=\"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-35.png 880w, http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-35-300x22.png 300w, http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-35-768x56.png 768w\" sizes=\"(max-width: 880px) 100vw, 880px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"827\" height=\"74\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-33.png\" alt=\"\" class=\"wp-image-1088\" srcset=\"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-33.png 827w, http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-33-300x27.png 300w, http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-content\/uploads\/sites\/4\/2022\/01\/image-33-768x69.png 768w\" sizes=\"(max-width: 827px) 100vw, 827px\" \/><\/figure>\n\n\n\n<p>Lien des tests : <a href=\"https:\/\/colab.research.google.com\/drive\/1lsyi4kzKrdVCxR3FQ2cmeYMdvIzQOsk_#scrollTo=1mrMzeLunz-d\">https:\/\/colab.research.google.com\/drive\/1lsyi4kzKrdVCxR3FQ2cmeYMdvIzQOsk_#scrollTo=1mrMzeLunz-d<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1 &#8211; Cr\u00e9ation de tableaux al\u00e9atoires d\u2019entiers Cr\u00e9ation d\u2019un tableau t de valeurs al\u00e9atoires \u00e0 trier Mesure de la dur\u00e9e d\u2019ex\u00e9cution d\u2019un programme A quoi correspond la variable debut ? Effectuez un test pour justifier la r\u00e9ponse. La variable debut correspond au moment o\u00f9 Tracer un nuage de points&nbsp;&nbsp; Exemple 10 points de la droite [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":1056,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-json\/wp\/v2\/posts\/1050"}],"collection":[{"href":"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-json\/wp\/v2\/comments?post=1050"}],"version-history":[{"count":23,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-json\/wp\/v2\/posts\/1050\/revisions"}],"predecessor-version":[{"id":1092,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-json\/wp\/v2\/posts\/1050\/revisions\/1092"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-json\/wp\/v2\/media\/1056"}],"wp:attachment":[{"href":"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-json\/wp\/v2\/media?parent=1050"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-json\/wp\/v2\/categories?post=1050"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/raphaelle\/wp-json\/wp\/v2\/tags?post=1050"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}