Created
February 28, 2017 11:08
-
-
Save georgy7/84a0d684020f34d2c7c5ff5317fabb7b to your computer and use it in GitHub Desktop.
D executable size experiment.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/++ | |
+ Experiment 2017-02-28. | |
+ Author: Георгий Устинов | |
+ License: CC0. | |
+ | |
+ Executable size on Linux x86_64 | |
+ LDC2 0.17.1 (DMD v2.068.2, LLVM 3.8.0) | |
+ | |
+ ldc2 dzip.d ............... 26.6 KiB (27 232) | |
+ ldc2 -release dzip.d ...... 26.5 KiB (27 176) | |
+ ldc2 -Os dzip.d ........... 20.2 KiB (20 736) | |
+ ldc2 -Oz dzip.d ........... 20.2 KiB (20 736) | |
+ ldc2 -release -Os dzip.d .. 20.2 KiB (20 696) | |
+ ldc2 -release -Oz dzip.d .. 20.2 KiB (20 696) | |
+ | |
+ But this is without `-static` flag. | |
+ So, if you run executable on the clean system. | |
+ sudo docker run -it -v /home/georgy/hostFolder/:/data ubuntu | |
+ # cd /data/ | |
+ # ./dzip test.txt test.zlib | |
+ ./dzip: error while loading shared libraries: libphobos2-ldc.so.68: cannot open shared object file: No such file or directory | |
+ | |
+ Сonclusion: | |
+ You can use zlib module to decompress resources like fonts, texts, etc. | |
+ But it makes sense only if your user already has phobos installed or | |
+ if you has *large* resource set, because statically linked executable | |
+ weight is at least 1.5-2 MiB (both DMD and LDC2). | |
+ | |
+ Also, currently, statically linked executables from LDC2 show the warnings, | |
+ that glibc still use some shared libraries. | |
+ Also, glibc has the big foot (~600 KiB, as I know). | |
+ http://www.etalabs.net/compare_libcs.html | |
+ TODO: Try to statically link with Musl inside Docker and then run on host system (Kubuntu). | |
+/ | |
module dzip; | |
import std.stdio : writeln; | |
import std.file; | |
import std.zlib; | |
void main(char[][] args) { | |
if (args.length != 4) { | |
writeln("Usage:\ndgzip -c input.txt ouput.zlib\ndgzip -d ouput.zlib input.txt"); | |
} | |
auto input = cast(ubyte[]) read(args[2]); | |
ubyte[] output; | |
if (args[1] == "-c") { | |
output = cast(ubyte[]) compress(input); | |
} else if (args[1] == "-d") { | |
output = cast(ubyte[]) uncompress(input); | |
} | |
write(args[3], output); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment