>>242
I don't pretend to be a genius. Its a "hacking for fun" stuff.
I'll use as many exotic and quirky ways to program as i want as long as it useful for me.
You can laugh that i spend time on some "bithacks" but i'm exploring various algorithms and their simplified forms to my leisure.
JavaScript is very good for prototyping the "abstract program"(like e.g.LISP), only when the stage of micro-optimization is reached the flaws of internals are exposed.
>>246
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define LEN 10000
inline unsigned long long rdtsc(){__asm{RDTSC}}
void main(){
int i, j, z;
unsigned long long c1, c2;
int arr[LEN];
for(i=0; i<LEN; i++) arr
[i] =rand()%10000-5000;
//with branch
c1 = rdtsc();
for(j=0;j<LEN;j++) z = arr[j]>0?arr[j]:-arr[j];
c2 = rdtsc();
printf("Cycles spent:%llu\n", c2-c1);
//bithax
c1 = rdtsc();
for(j=0;j<LEN;j++) z =arr[j]*(((arr[j]>=0)<<1)-1);
c2 = rdtsc();
printf("Cycles spent:%llu\n", c2-c1);
}
result:
C:\Program Files\dmc8.50\dmc\dm\bin\code>abs
Cycles spent:30108
Cycles spent:30109