Skip to content

Instantly share code, notes, and snippets.

@warrenseine
Last active August 29, 2015 14:19
Show Gist options
  • Save warrenseine/cc19097d07496c843f16 to your computer and use it in GitHub Desktop.
Save warrenseine/cc19097d07496c843f16 to your computer and use it in GitHub Desktop.
Emscripten size comparison between <iostream>, fprintf, and write
#include <stdio.h>
int main()
{
fprintf(stdout, "hello world\n");
}
#include <iostream>
int main()
{
std::cout << "hello world" << std::endl;
}
#include <unistd.h>
int main()
{
write(1, "hello world\n", sizeof("hello world\n"));
}
all: hello-fprintf.html hello-iostream.html hello-write.html
hello-fprintf.html: hello-fprintf.cpp
em++ -std=c++11 -O2 hello-fprintf.cpp -o hello-fprintf.bc
emcc -O2 hello-fprintf.bc -o hello-fprintf.html
hello-iostream.html: hello-iostream.cpp
em++ -std=c++11 -O2 hello-iostream.cpp -o hello-iostream.bc
emcc -O2 hello-iostream.bc -o hello-iostream.html
hello-write.html: hello-write.cpp
em++ -std=c++11 -O2 hello-write.cpp -o hello-write.bc
emcc -O2 hello-write.bc -o hello-write.html
clean:
rm -f *.bc *.js *.html *.html.map *.html.mem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment