# Question about Crystal, Compiled Code, and Performance

**URL:** <https://forum.crystal-lang.org/t/question-about-crystal-compiled-code-and-performance/753>\
**Category:** Help & Support\
**Created:** [May 9, 2019, 4:16pm UTC](https://forum.crystal-lang.org/t/question-about-crystal-compiled-code-and-performance/753 "2019-05-09T16:16:56Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![sol.vin](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/sol.vin/32/73_2.png) [@sol.vin](https://forum.crystal-lang.org/u/sol.vin)\
**Post date:** [May 10, 2019, 4:38am UTC](https://forum.crystal-lang.org/t/question-about-crystal-compiled-code-and-performance/753/7 "2019-05-10T04:38:32Z")

</div>

I know about clang, what I meant was that you can’t write a piece of code in Crystal and emit LLVM and expect it will be exactly the same as an identical piece of LLVM emitted C code. If I’m not mistaken, the two piece of code will have some big differences, like GC, std classes, etc.

For example, I wrote two programs, one in Crystal, and one in C, both of them do about the same thing, print the string `"HELLO!\n"`

**test.cr**

```auto
print "HELLO!\n"
```

**test.c**

```auto
#include <stdio.h>

int main()
{
    printf("HELLO!\n");
    return 0;
}
```

I then made each emit LLVM-IR using the following commands

```auto
crystal-vs-c$ crystal build test.cr --emit llvm-ir -o test-cr.ll
crystal-vs-c$ clang -emit-llvm -c test.c -S -o test-c.ll
```

The difference between the two is night and day, the C code ends up being a succinct 25 lines of LLVM-IR where the Crystal code comes out to around 70000 lines of LLVM-IR. I tried emitting LLVM without the prelude but, it won’t work since it can’t find `print` without it.

> <https://gist.github.com/redcodefinal/4aee655c9a6ccbe0669b6cbecf352cf6>

GC/reference overhead are both good points though, I didn’t think of that.

Again not a master of LLVM so maybe I’m missing something else but, I would love to learn more about LLVM internals from someone who works with it all the time. 🙂

---

_[View the full topic](https://forum.crystal-lang.org/t/question-about-crystal-compiled-code-and-performance/753)._
