I want to learn about performance impact of different calculations and influences/optimizations like compiler flags, use of SSE, AVX etc.

I'm going to code some small subroutines which will take place in almost every arithmetic operation in a special program, thus good code, portability and performance do! matter.

Insofar the questions:

* is the code below meaningful?
* should it be improved?
* or is 'better' already in the field and i just overlooked it?
* is similar possible in 'C'?

I'm new here and **not** a coder, 'script kiddie' at best, the program is 'picked together' at SO and cppreference, thus 'bear with me' and I beg your pardon for any stupidity or errors.

I have asked the question with a prior version at SO, some tips from there are implemented.

```
// compile with e.g. 
// g++ -O1 timing_operations_2.c -o timing_operations_2 -lm
// impressive differenes with  
// g++ -O9 timing_operations_2.c -o timing_operations_2 -lm
// but think that's reg. supressing code with no further use

// not necessary? 
// #include <algorithm>
// #include <ctime>
#include <iostream> // reg. cout, 
#include <iomanip>  // reg. put_time, setpreision, 
#include <chrono>   // reg. chrono, 
#include <thread>   // reg. thread, 
#include <math.h>   // reg. pow( x, y ), 

using namespace std; 
using namespace std::literals; // enables the usage of 24h, 1ms, 1s instead of
                               // e.g. std::chrono::hours(24), accordingly

void slow_motion()
{
        std::cout << "Hello waiter\n" << std::flush;
    auto start = std::chrono::high_resolution_clock::now();
    std::cout << "Hi! in one second I'll die! :-( " << endl;
    std::this_thread::sleep_for(1000ms);
    auto end = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double, std::milli> elapsed = end-start;
    std::cout << "urrrrggghhhh!     took: " << elapsed.count() << " ms\n";
}

int main()
{
    int amount = 100000;    // size of testfield
    int i = 0;      // counter
    double x1 = 0;      // working value

    std::cout << std::setprecision(16) << std::fixed;

    const std::chrono::time_point<std::chrono::system_clock> now =
            std::chrono::system_clock::now();

        const std::time_t t_c = std::chrono::system_clock::to_time_t(now - 24h);
    std::cout << "24 hours ago, the time was "
        << std::put_time(std::localtime(&t_c), "%F %T.\n") << std::flush;

        const std::chrono::time_point<std::chrono::steady_clock> start =
        std::chrono::steady_clock::now();

        slow_motion();

        const auto end = std::chrono::steady_clock::now();

        std::cout
        << "Slow calculations took "
        << std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() << "µs ≈ "
        << (end - start) / 1ms << "ms ≈ " // almost equivalent form of the above, but
        << (end - start) / 1s << "s.\n";  // using milliseconds and seconds accordingly

// preparing testvalues for timing, 

    double testme[amount];

    for( i = 0; i < amount; ++i )
    {
            testme[i] = rand() / pow( 2, 16 );
    }

// timing ' x / 2 ', 
    auto start_1 = std::chrono::high_resolution_clock::now();
    for( i = 0; i < amount; ++i )
    {
        x1 = testme[i] / 2;
//      cout << "' x / 2:     " << x1 << "\n";
    }
    auto end_1 = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double, std::milli> elapsed = end_1-start_1;
        std::cout
        << "calculating " << amount << " times ' = x / 2 ' took         " 
        << std::chrono::duration_cast<std::chrono::microseconds>(end_1 - start_1).count() << "µs ≈ "
        << (end_1 - start_1) / 1ms << "ms ≈ " // almost equivalent form of the above, but
        << (end_1 - start_1) / 1s << "s.\n";  // using milliseconds and seconds accordingly

// timing ' x / 2 ', a second time aginst caching influences, 
    start_1 = std::chrono::high_resolution_clock::now();
    for( i = 0; i < amount; ++i )
    {
        x1 = testme[i] / 2;
//      cout << "' x / 2:     " << x1 << "\n";
    }
    end_1 = std::chrono::high_resolution_clock::now();
    elapsed = end_1-start_1;
        std::cout
        << "calculating " << amount << " times ' = x / 2 ' took         " 
        << std::chrono::duration_cast<std::chrono::microseconds>(end_1 - start_1).count() << "µs ≈ "
        << (end_1 - start_1) / 1ms << "ms ≈ " // almost equivalent form of the above, but
        << (end_1 - start_1) / 1s << "s.\n";  // using milliseconds and seconds accordingly

// timing ' x / 3 ', 
    start_1 = std::chrono::high_resolution_clock::now();
    for( i = 0; i < amount; ++i )
    {
        x1 = testme[i] / 3;
//      cout << "' x / 3:     " << x1 << "\n";
    }
    end_1 = std::chrono::high_resolution_clock::now();
    elapsed = end_1-start_1;
        std::cout
        << "calculating " << amount << " times ' = x / 3 ' took         " 
        << std::chrono::duration_cast<std::chrono::microseconds>(end_1 - start_1).count() << "µs ≈ "
        << (end_1 - start_1) / 1ms << "ms ≈ " // almost equivalent form of the above, but
        << (end_1 - start_1) / 1s << "s.\n";  // using milliseconds and seconds accordingly

// timing ' (int)x ', 
    start_1 = std::chrono::high_resolution_clock::now();
    for( i = 0; i < amount; ++i )
    {
        x1 = (int)testme[i];
//      cout << "' (int)x ':     " << x1 << "\n";
    }
    end_1 = std::chrono::high_resolution_clock::now();
    elapsed = end_1-start_1;
        std::cout
        << "calculating " << amount << " times ' = (int)x ' took        " 
        << std::chrono::duration_cast<std::chrono::microseconds>(end_1 - start_1).count() << "µs ≈ "
        << (end_1 - start_1) / 1ms << "ms ≈ " // almost equivalent form of the above, but
        << (end_1 - start_1) / 1s << "s.\n";  // using milliseconds and seconds accordingly

// timing ' pow( 10, x ) ', 
    start_1 = std::chrono::high_resolution_clock::now();
    for( i = 0; i < amount; ++i )
    {
        x1 = pow( 10, testme[i] );
//      cout << "' (int)x ':     " << x1 << "\n";
    }
    end_1 = std::chrono::high_resolution_clock::now();
    elapsed = end_1-start_1;
        std::cout
        << "calculating " << amount << " times ' = pow( 10, x ) ' took " 
        << std::chrono::duration_cast<std::chrono::microseconds>(end_1 - start_1).count() << "µs ≈ "
        << (end_1 - start_1) / 1ms << "ms ≈ " // almost equivalent form of the above, but
        << (end_1 - start_1) / 1s << "s.\n";  // using milliseconds and seconds accordingly

    return ( 0 ); 
}

```