This file contains 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 std.stdio; | |
import std.range; | |
import std.datetime; | |
import std.conv; | |
import std.algorithm; | |
import std.traits; | |
import std.typecons; | |
import std.functional; | |
private void doNotOptimizeAway(T)(auto ref T t) |
This file contains 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
#!/usr/bin/env dub | |
/+ dub.json: | |
{ | |
"name": "bench_flex", | |
"dependencies": { | |
"mir": {"path": "."}, | |
}, | |
"dflags-ldc": ["-mcpu=native"] | |
} | |
+/ |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
void main() { | |
import std.stdio; | |
import std.meta : AliasSeq; | |
import std.math : PI, sin; | |
import core.stdc.math : sin_c = sin; | |
foreach (S; AliasSeq!(float, double, real)) | |
{ | |
S pi = PI; | |
writefln("x: %12s, x_c: %12s, x_c_pi: %12s", sin(S(PI)), sin_c(S(PI)), sin_c(pi)); | |
} |
This file contains 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
string[] glob(string pattern) | |
{ | |
import std.string; | |
string[] results; | |
glob_t glob_result; | |
glob(pattern.toStringz, 0, null, &glob_result); | |
for (uint i = 0; i < glob_result.gl_pathc; i++) | |
{ | |
results ~= glob_result.gl_pathv[i].fromStringz().idup; | |
} |
This file contains 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
fun: pow | |
std.math.pow = 13 secs, 743 ms, 902 μs, and 7 hnsecs | |
core.stdc.pow = 12 secs, 490 ms, 213 μs, and 2 hnsecs | |
fun: exp | |
std.math.exp = 6 secs, 905 ms, and 644 μs | |
core.stdc.exp = 16 secs, 336 ms, 330 μs, and 4 hnsecs | |
fun: exp2 | |
std.math.exp2 = 3 secs, 338 ms, 447 μs, and 9 hnsecs | |
core.stdc.exp2 = 5 secs, 244 ms, 528 μs, and 6 hnsecs | |
fun: sin |
This file contains 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
auto setBit(ubyte idx)(ulong bitfield) | |
{ | |
enum mask = 1UL << idx; | |
return bitfield |= mask; | |
} | |
ulong setBit(ulong bitfield, ulong idx) | |
{ | |
ulong mask = 1UL << idx; | |
return bitfield |= mask; |
This file contains 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
S fun(S)(in S x) | |
{ | |
return -1 / x; | |
} | |
void main() | |
{ | |
alias S = double; // same for float | |
S i = fun!S(3); | |
assert(i == S(-1) / 3); // this lines passes |
This file contains 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 std.stdio; | |
alias S = float; | |
float shL = 0x1.1b95eep-4; // -0.069235 | |
float shR = 0x1.9c7cfep-7; // -0.012588 | |
F fun(F)(F x) | |
{ | |
return 1.0 + x * 2; | |
} |
This file contains 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
void main() | |
{ | |
alias S = float; | |
S s1 = 0x1.24c92ep+5; | |
S s2 = -0x1.1c71c8p+0; | |
import std.math : std_pow = pow; | |
import core.stdc.stdio : printf; | |
import core.stdc.math: powf; |