Commit 907675e0 by CHAMONT David

Better exercice !

parent 40d2cd71
 ... ... @@ -1006,12 +1006,15 @@ "source": [ "# Exercice\n", "\n", "Rather than looking at each isolated code line, it is often profitable to take a look at the big picture : how to simply move one part of the computation, so to get exactly the same output, a lot faster ?" "Let's assume that we always run the program below with a `degree`which is even.\n", "1. Replace `val *= data` with `val *= data*data`, and `j\n", "#include \n", "#include \n", "\n", "int const SIZE = 1024 ;\n", "int const REPEAT = 100000 ;\n", "\n", "using Array = std::array ;\n", "#include \n", "#include \n", "\n", "void randomize( Array & x ) {\n", " srand(1) ;\n", " for ( int i=0 ; i generate( int size )\n", " {\n", " std::valarray datas(size) ;\n", " for ( double & data : datas )\n", " { data = std::rand()/(RAND_MAX+1.) ; }\n", " return datas ;\n", " }\n", "\n", "void multiply( Array const & x, Array & y ) {\n", " for ( int r=0 ; r const & datas, int degree )\n", " {\n", " double res = 0 ;\n", " for ( double data : datas )\n", " {\n", " double val = 1 ; \n", " for ( int j=0 ; j> tmp.operations.py\n", "for i in 0 1 2 3 4 5 6 7 8 9\n", "do \\time -f \"t += %U\" -a -o ./tmp.operations.py ./tmp.operations.exe \$* >> /dev/null\n", "done\n", "echo \"print('(~ {:.3f} s)'.format(t/10.))\" >> tmp.operations.py\n", "python3 tmp.operations.py" "g++ -std=c++17 -O3 tmp.operations.cpp -o tmp.operations.exe\n", "time ./tmp.operations.exe \$*" ] }, { "cell_type": "code", "execution_count": 523, "execution_count": 546, "metadata": { "slideshow": { "slide_type": "subslide" "slide_type": "skip" } }, "outputs": [ ... ... @@ -1113,13 +1108,16 @@ "name": "stdout", "output_type": "stream", "text": [ "67.5054\n", "(~ 0.142 s)\n" "0.656155\r\n", "\r\n", "real\t0m1.767s\r\n", "user\t0m1.767s\r\n", "sys\t0m0.000s\r\n" ] } ], "source": [ "!bash -l ./tmp.operations.sh" "!bash -l ./tmp.operations.sh 1024 65536" ] }, { ... ...
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!