On Monday, 22 January 2024 at 13:48:20 UTC, Andrea Fontana wrote:
> On Monday, 22 January 2024 at 13:47:34 UTC, Andrea Fontana wrote:
> On Monday, 22 January 2024 at 10:23:55 UTC, ryuukk_ wrote:
> On Monday, 22 January 2024 at 10:08:16 UTC, Andrea Fontana wrote:
> On Sunday, 14 January 2024 at 09:04:32 UTC, Walter Bright wrote:
> On 9/28/2023 5:42 AM, deadalnix wrote:
> 1/ Downcast to final classes.
This has a PR for it now.
https://github.com/dlang/dmd/pull/16032
Why md5 and not a faster method?
Andrea
That is good opportunity to submit a PR, try it, it's not that hard and is rewarding
I know: I've already submitted PR to dmd and phobos :)
For example, this one. Easy, fast, insecure (who cares, in this case).
http://www.isthe.com/chongo/tech/comp/fnv/
Andrea
The right one is FNV-1a:
http://www.isthe.com/chongo/src/fnv/hash_32a.c
FNV1A is used for hashOf
. HashOf seems to be a lot faster than md5 only when you're dealing with smaller strings. I've done a test online and you'll see, this won't do actual difference in compilation time:
import std;
auto test(T)(scope T delegate() dg)
{
import std.datetime.stopwatch;
StopWatch sw = StopWatch(AutoStart.yes);
scope(exit){writeln(sw.peek.total!"msecs");}
return dg();
}
string repeat(string a, int n)
{
char[] ret = new char[](a.length*n);
foreach(i; 0..n)
ret[i*a.length..(i+1)*a.length] = a[];
return cast(string)ret;
}
void main()
{
import std.digest.md;
foreach(count; [1, 5, 10, 15, 25, 35, 50, 100, 200])
{
string testString = "a".repeat(count);
writeln("\nResult for 1_000_000 times executing hashes for a string if size ", count);
test(()
{
foreach(i; 0..1_000_000)
hashOf(testString);
});
test(()
{
foreach(i; 0..1_000_000)
md5Of(testString);
});
}
}
This is the result I have for this program:
Result for 1_000_000 times executing hashes for a string if size 1
12
130
Result for 1_000_000 times executing hashes for a string if size 5
25
132
Result for 1_000_000 times executing hashes for a string if size 10
36
129
Result for 1_000_000 times executing hashes for a string if size 15
41
124
Result for 1_000_000 times executing hashes for a string if size 25
54
127
Result for 1_000_000 times executing hashes for a string if size 35
69
120
Result for 1_000_000 times executing hashes for a string if size 50
94
116
Result for 1_000_000 times executing hashes for a string if size 100
176
217
Result for 1_000_000 times executing hashes for a string if size 200
379
394
As you see, this is a result for 1 million times hashing strings. I can't even think in many situations people would be doing 1 million time hashings. For a big program, you'll probably get 200 string literals. And if you test, it is still 0 milliseconds. So, MD5 is a pretty solution for that problem, and this would be too much effort for actually no gain at all, it could even create duplicate strings for no millisecond gain :)