/* Collection of code snippets by Arne Vajhøj */
/* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) */
#include <stdio.h>
#include <time.h>

#define N 1000000000

void check(int v, int expected);

int main()
{
    int i,v;
    time_t t1,t2,t3,t4,t5,t6;
    t1 = time(NULL);
    for(i=0;i<N;i++)
    {
        v = 1;
        v = v + 1;
        check(v,2);
        v = v + 1;
        check(v,3);
        v = v + 1;
        check(v,4);
        v = v + 1;
        check(v,5);
        v = v + 1;
        check(v,6);
        v = v + 1;
        check(v,7);
        v = v + 1;
        check(v,8);
        v = v + 1;
        check(v,9);
        v = v + 1;
        check(v,10);
        v = v + 1;
        check(v,11);
    }
    t2 = time(NULL);
    printf("None: %.1f\n",difftime(t2,t1));
    t3 = time(NULL);
    for(i=0;i<N;i++)
    {
        v = 1;
        v = (v << 1) + 1;
        check(v,3);
        v = (v << 1) + 1;
        check(v,7);
        v = (v << 1) + 1;
        check(v,15);
        v = (v << 1) + 1;
        check(v,31);
        v = (v << 1) + 1;
        check(v,63);
        v = (v << 1) + 1;
        check(v,127);
        v = (v << 1) + 1;
        check(v,255);
        v = (v << 1) + 1;
        check(v,511);
        v = (v << 1) + 1;
        check(v,1023);
        v = (v << 1) + 1;
        check(v,2047);
    }
    t4 = time(NULL);
    printf("Shift: %.1f\n",difftime(t4,t3));
    t5 = time(NULL);
    for(i=0;i<N;i++)
    {
        v = 1;
        v = v * 2 + 1;
        check(v,3);
        v = v * 2 + 1;
        check(v,7);
        v = v * 2 + 1;
        check(v,15);
        v = v * 2 + 1;
        check(v,31);
        v = v * 2 + 1;
        check(v,63);
        v = v * 2 + 1;
        check(v,127);
        v = v * 2 + 1;
        check(v,255);
        v = v * 2 + 1;
        check(v,511);
        v = v * 2 + 1;
        check(v,1023);
        v = v * 2 + 1;
        check(v,2047);
    }
    t6 = time(NULL);
    printf("Mul: %.1f\n",difftime(t6,t5));
    return 0;
}
