Skip to content

Instantly share code, notes, and snippets.

@wilzbach
wilzbach / filter.d
Last active June 20, 2017 01:15
For all Dscanner checks find all failing module
#!/usr/bin/env dub
/++ dub.sdl:
name "filter"
dependency "inifiled" version="~>1.0.1"
dependency "dscanner" version="~>0.4.0"
+/
import analysis.config;
import dparse.lexer : StringCache;
import dsymbol.modulecache : ModuleCache;
@wilzbach
wilzbach / benchmark.md
Created May 5, 2017 14:56
minmaxElement comparison

RandomAccess

ldc -release -O5 -mcpu=native test.d && ./test
reduce!(min,max) = 7 secs, 722 ms, 265 μs, and 4 hnsecs
fold.minMax     = 5 secs, 770 ms, and 427 μs
minmaxElement   = 5 secs, 410 ms, and 31 μs
minmaxElementInPairs = 15 secs, 362 ms, 724 μs, and 3 hnsecs
#!/usr/bin/env rdmd
import std.algorithm, std.array, std.conv, std.mmfile, std.range, std.stdio, std.bigint;
void main(string[] args)
{
if (args.length < 2)
{
writeln("No input file given.");
return;

With mapping

> ldc -release -O5 -mcpu=native test.d && ./test
reduce!(min,max) = 16 secs, 745 ms, 280 μs, and 1 hnsec
fold.minMax     = 13 secs, 756 ms, 979 μs, and 4 hnsecs
minmaxElement   = 14 secs, 179 ms, 390 μs, and 1 hnsec
@wilzbach
wilzbach / results
Created February 28, 2017 19:01
benchmark std.algorithm.searching.extremum with and without identity specialization
> dmd -release -O test.d && ./test
extremum.before = 54 secs, 12 ms, 347 μs, and 9 hnsecs
extremum.after = 29 secs, 521 ms, 896 μs, and 5 hnsecs
> ldc -release -O3 test.d && ./test
extremum.before = 13 secs, 186 ms, 176 μs, and 4 hnsecs
extremum.after = 2 secs, 241 ms, 454 μs, and 9 hnsecs
@wilzbach
wilzbach / How_to_run.md
Created February 20, 2017 15:34
Set possibly immutable variables in Phobos to const
  1. Enable the DScanner check

In the .dscanner.ini, set the immutable check to enable:

could_be_immutable_check="enabled"
  1. Generate a file with all Dscanner warnings
@wilzbach
wilzbach / result
Created February 19, 2017 15:56
walkBack: use Unqual & foreach vs. checking empty twice
> ldc -O5 -release -boundscheck=off walkBack.d && ./walkBack
walkBack.foreach = 3 secs, 772 ms, 463 μs, and 6 hnsecs
walkBack.while = 4 secs, 191 ms, 417 μs, and 8 hnsecs
@wilzbach
wilzbach / fixer.d
Last active February 16, 2017 01:27
Fix indentation warnings for Phobos
#!/usr/bin/env rdmd
auto parenDiff(S)(S ss)
{
auto count = 0;
foreach (s; ss)
{
switch (s)
{
case '(': count++; break;
@wilzbach
wilzbach / result
Last active January 13, 2017 08:09
std.random.uniform vs. bitwise
> ldc -O5 -release -boundscheck=off test.d && ./test 1 2 8 256 1024 65536
benchmark: 1 (bits: 1)
random.uniform = 742 ms, 824 μs, and 5 hnsecs
random.bitwise = 218 ms, 972 μs, and 9 hnsecs
random.uniform.fixed = 592 ms, 647 μs, and 2 hnsecs
benchmark: 2 (bits: 2)
random.uniform = 746 ms, 839 μs, and 5 hnsecs
random.bitwise = 497 ms and 189 μs
random.uniform.fixed = 594 ms, 196 μs, and 1 hnsec
import std.algorithm, std.conv, std.datetime, std.functional, std.range, std.stdio, std.traits, std.typecons;
private void doNotOptimizeAway(T)(auto ref T t)
{
import core.thread : getpid;
import std.stdio : writeln;
if(getpid() == 1) {
writeln(*cast(char*)&t);
}
}