Skip to content

Instantly share code, notes, and snippets.

@LennyLip
Created November 28, 2019 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LennyLip/ba5b567ac680c89e62dd010934d55abd to your computer and use it in GitHub Desktop.
Save LennyLip/ba5b567ac680c89e62dd010934d55abd to your computer and use it in GitHub Desktop.
#include <emscripten.h>
// #include <stdio.h>
#include <stdlib.h>
char str[] = "Function from C (Web Assemblly) called!";
EMSCRIPTEN_KEEPALIVE
char* functionFromC () {
return &str[0];
}
EMSCRIPTEN_KEEPALIVE
double loadTest () {
// clock_t start, end;
int start, end;
double cpu_time_used;
int num = 1, primes = 0;
int limit = 150000;
// don't work
// start = emscripten_get_now();
for (num = 1; num <= limit; num++) {
int i = 2;
while(i <= num) {
if(num % i == 0)
break;
i++;
}
if(i == num)
primes++;
}
return primes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment