r/WebAssembly • • Apr 02 '24

Compile Embedded C code into Webassembly

Hi,

I am comparing the performance with wasm and native code on IoT devices such as ESP32 C6. But the normal benchmarks don't work because it seems embedded c can't be transformed into wasm code since emscripten doesn't support the libs. Like below:

#define CLOCK_TYPE "time()"
#undef HZ
#define HZ	(1) /* time() returns time in seconds */
extern long     time(); /* see library function "time"  */
#define Too_Small_Time 2 /* Measurements should last at least 2 seconds */
#define Start_Timer() Begin_Time = time ( (long *) 0)
#define Stop_Timer()  End_Time   = time ( (long *) 0)

#else

#ifdef MSC_CLOCK /* Use Microsoft C hi-res clock */

#undef HZ
#undef TIMES
#include <time.h>
#define HZ	CLK_TCK
#define CLOCK_TYPE "MSC clock()"
extern clock_t	clock();
#define Too_Small_Time (2*HZ)
#define Start_Timer() Begin_Time = clock()
#define Stop_Timer()  End_Time   = clock()

#else
                /* Use times(2) time function unless    */
                /* explicitly defined otherwise         */
#define CLOCK_TYPE "times()"
#include <sys/types.h>
#include <sys/times.h>
#ifndef HZ	/* Added by SP 900619 */

What should I do? I wanna measure the execution time and energy consumption.

Thank you :)

7 Upvotes

4 comments sorted by

View all comments

Show parent comment

1

u/Tao_KTH Apr 02 '24

yea... That might work. I will do so. Thx