Posts

Showing posts with the label C

An Introduction to JS-Ctypes

Update If you have time follow the whole story in es-discuss mailing list while if you don't have time here the quick summary: js-ctypes purpose is different from JS.next typed structs/arrays so it looks like it was my mistake to compare tomatoes and potatoes. I bet everybody else in this world could have compared these two different beasts due identical name, look, and similar usage. If ctypes are not used outside JS these are not JIT optimized in any case so now we know why performances are so slow compared with JS code. On new Struct({literal:pairs}) VS new Struct(literal = pairs) there is still no answer and even if it's obviously possible to avoid an object creation per each created instance, recycling a single object and refreshing its properties same as we could do with properties descriptors and Object.defineProperty I have pointed this out in that way on purpose since I can already see a massive usage of that unoptimized pattern and I would like to know that engi...

Mousetrap in C language

Just for fun, and performances are horribles as well in new C version, performances are great until 5000 cards, so I need to remove some dust from my good old ANSI C book :D New version, compatible with gcc compiler. To create and use the executable, gcc Mousetrap.c Then call the file Mousetrap 5, for example, to obtain 1,3,2,5,4 Works quickly until 5000 results, requires a monster PC for 1000000 Google limit (algo is still not perfect, but this can generate an entire deck, instead of getting only that index, for each index) #include <stdlib.h> int *perfectDeck(int cards); int main(int argc, char **argv){ if(--argc){ *argv++; int i = 0, cards = atoi(*argv); if(cards > 0){ int *result = perfectDeck(cards); printf("%i", result[i++]); while(i printf(" %i", result[i++]); free(result); } } return 0; } int *perfectDeck(int cards){ i...