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
| // INSTRUCTIONS: | |
| // Compile with `gcc -s -O3 -flto -o bench bench.c` | |
| // Run with `./bench 100000 10000` | |
| // IMPORTANT: | |
| // The two parameters are REQUIRED and are the numbers for: | |
| // 1. How many points in the array. | |
| // 2. How many times to cycle through the array. | |
| // | |
| // The numbers are not multiplied to ensure the compiler can't cheat. |
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
| {.this: self.} | |
| import syntax | |
| type | |
| Person = object | |
| age: int | |
| name: string | |
| var | |
| boys: seq[Person] |
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
| import tables | |
| # --- | |
| type ID = int | |
| var nextTypeID {.compileTime.}: ID | |
| proc typeID(T:typedesc): ID = | |
| const id = nextTypeID |
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
| type | |
| CanDance = concept x | |
| dance(x) # `x` is anything that has a `dance` procedure | |
| proc doBallet(dancer: CanDance) = | |
| # `dancer` can be anything that `CanDance` | |
| dance(dancer) | |
| # --- |
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
| type | |
| CArray{.unchecked.}[T] = ptr array[1, T] | |
| type | |
| A = object | |
| items: ptr float | |
| B = object | |
| items: CArray[float] |
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
| import macros | |
| # --- --- --- # | |
| type | |
| Base* {.pure inheritable.} = object | |
| Comp* {.pure inheritable.} = object | |
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
| import brim | |
| # --- | |
| type | |
| Position = object | |
| x, y: float | |
| Velocity = object |
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
| type | |
| Automatic = object | |
| Explicit = object | |
| AutoRef[T] = ptr[Automatic, T] | |
| ExplicitRef[T] = ptr[Explicit, T] | |
| proc `[]`[T](r:AutoRef[T]): var T = | |
| echo "Automatic" | |
| return r[] |
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
| type | |
| Sprite {.pure inheritable.} = object | |
| x, y: float | |
| image: string | |
| Fighter = object of Sprite | |
| health: float | |
| strength: float | |
| proc move(s:var Sprite, x, y:float) = |
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
| # Inheritance implies runtime memory overhead, so using it for small things like Particles | |
| # is not ideal even though inheritance (to a Sprite base-type for instance) might be useful. | |
| # We could 'auto compose' types instead as a way to use limited inheritance without it's costs | |
| type | |
| Sprite = object | |
| resource: Image | |
| position: Vector | |
| rotation: Vector |
NewerOlder