On 04/29/2011 07:13 AM, Jacob Carlborg wrote:
On 2011-04-28 21:46, Timon Gehr wrote:
Andrei Alexandrescu wrote:
On 4/28/11 11:00 AM, Alexander wrote:
On 28.04.2011 17:46, Andrej Mitrovic wrote:
It works, but it makes the if statement ugly again. :)
Well, just a bit - still much better
On 4/29/11 8:50 AM, Denis Koroskin wrote:
On Thu, 28 Apr 2011 03:10:15 +0400, Andrej Mitrovic
andrej.mitrov...@gmail.com wrote:
I often see code written like this:
if (value == somevalue ||
value == someothervalue ||
value == yetanothervalue);
You could use the switch statement. But that
On Apr 30, 11 03:12, Andrei Alexandrescu wrote:
On 4/29/11 8:50 AM, Denis Koroskin wrote:
On Thu, 28 Apr 2011 03:10:15 +0400, Andrej Mitrovic
andrej.mitrov...@gmail.com wrote:
I often see code written like this:
if (value == somevalue ||
value == someothervalue ||
value == yetanothervalue);
On 4/29/11 2:44 PM, KennyTM~ wrote:
[snip]
You need to replace the assert and compile with -O -release -inline. My
results:
find in array: 163
compile-time 1: 10
either: 17
straight comparison: 8
compile-time 2: 11
Code:
import std.datetime, std.algorithm, std.typecons, std.stdio;
auto
On 29.04.2011 21:58, Andrei Alexandrescu wrote:
You need to replace the assert and compile with -O -release -inline. My
results:
[snip]
Still, straight comparison wins - 2x faster ;)
/Alexander
On Sat, 30 Apr 2011 03:19:37 +0400, Alexander aldem+dm...@nk7.net wrote:
On 29.04.2011 21:58, Andrei Alexandrescu wrote:
You need to replace the assert and compile with -O -release -inline. My
results:
[snip]
Still, straight comparison wins - 2x faster ;)
/Alexander
That's just an
On 4/29/11 6:21 PM, Denis Koroskin wrote:
On Sat, 30 Apr 2011 03:19:37 +0400, Alexander aldem+dm...@nk7.net wrote:
On 29.04.2011 21:58, Andrei Alexandrescu wrote:
You need to replace the assert and compile with -O -release -inline.
My results:
[snip]
Still, straight comparison wins - 2x
On 30.04.2011 01:23, Andrei Alexandrescu wrote:
Yah. I think the difference is immaterial outside inner loops. If it were
like 20x slower that would've been a problem.
Outside of inner loops even 20x is not a real problem ;)
/Alexander
On 30.04.2011 01:21, Denis Koroskin wrote:
That's just an optimizer issue. Even if you replace the code body with
return false; (i.e. not found) it's STILL slower than straight comparison.
2x? Hardly, IMHO.
/Alexander
On 4/29/2011 6:19 PM, Alexander wrote:
On 29.04.2011 21:58, Andrei Alexandrescu wrote:
You need to replace the assert and compile with -O -release -inline. My results:
[snip]
Still, straight comparison wins - 2x faster ;)
/Alexander
When understanding the CPU platform you are on, one of
On 2011-04-28 18:20, Andrej Mitrovic wrote:
Well, DMD accepts this kind of syntax already:
if (value == val1, val2, val3) { }
I think this turns the expression value==val1 into a bool, and then
turns val2 and val3 into bools and compares against each of them. Or
something like that. It's odd
On 29/04/2011 10:31, Jacob Carlborg wrote:
On 2011-04-28 18:20, Andrej Mitrovic wrote:
Well, DMD accepts this kind of syntax already:
if (value == val1, val2, val3) { }
I think this turns the expression value==val1 into a bool, and then
turns val2 and val3 into bools and compares against each
On 29/04/11 10:31 AM, Jacob Carlborg wrote:
On 2011-04-28 18:20, Andrej Mitrovic wrote:
Well, DMD accepts this kind of syntax already:
if (value == val1, val2, val3) { }
I think this turns the expression value==val1 into a bool, and then
turns val2 and val3 into bools and compares against
On 2011-04-28 21:46, Timon Gehr wrote:
Andrei Alexandrescu wrote:
On 4/28/11 11:00 AM, Alexander wrote:
On 28.04.2011 17:46, Andrej Mitrovic wrote:
It works, but it makes the if statement ugly again. :)
Well, just a bit - still much better than (var == ... || var = ...||
var == ...
On 2011-04-29 14:22, Peter Alexander wrote:
On 29/04/11 10:31 AM, Jacob Carlborg wrote:
On 2011-04-28 18:20, Andrej Mitrovic wrote:
Well, DMD accepts this kind of syntax already:
if (value == val1, val2, val3) { }
I think this turns the expression value==val1 into a bool, and then
turns val2
On Thu, 28 Apr 2011 03:10:15 +0400, Andrej Mitrovic
andrej.mitrov...@gmail.com wrote:
I often see code written like this:
if (value == somevalue ||
value == someothervalue ||
value == yetanothervalue);
You could use the switch statement. But that introduces indentation,
and is rarely
On 28.04.2011 01:10, Andrej Mitrovic wrote:
I really like the in keyword, and I also like hashes since they can
potentially speed up look-ups compared to conventional arrays.
The problem is, potentially means for [relatively] large sets, as hashing
overhead will kill the benefits for
You seem to be right. It looks like DMD is pretty good at optimizing
if statements. The Hash version is quite a bit slower actually.
Well, that's what happens when I assume things. :)
Here's a little benchmark of searching an array and hash of randomly
generated strings:
On 28.04.2011 16:25, Andrej Mitrovic wrote:
Here's a little benchmark of searching an array and hash of randomly
generated strings:
Make it 16 values and run again :) Sure, the more elements we have, the
better hash performs.
But in case of ints/floats, for instance, for small sets
InSet!(var, values...).
That wouldn't work because var is known only at runtime. Ideally I'd
like to write something like:
string needle = foo;
if (needle.InSet!(bar, barfoo, doo, foo)) { }
And InSet would mixin and call a function such as:
bool inSet(string needle)
{
if (needle = bar ||
On 28/04/11 4:24 PM, Andrej Mitrovic wrote:
InSet!(var, values...).
That wouldn't work because var is known only at runtime. Ideally I'd
like to write something like:
string needle = foo;
if (needle.InSet!(bar, barfoo, doo, foo)) { }
And InSet would mixin and call a function such as:
bool
It works, but it makes the if statement ugly again. :)
On 28.04.2011 17:46, Andrej Mitrovic wrote:
It works, but it makes the if statement ugly again. :)
Well, just a bit - still much better than (var == ... || var = ... || var
== ... ...), don't you think so? ;)
If compiler would support special in usage, automatically expanding values
on
On 4/28/11 11:00 AM, Alexander wrote:
On 28.04.2011 17:46, Andrej Mitrovic wrote:
It works, but it makes the if statement ugly again. :)
Well, just a bit - still much better than (var == ... || var = ... || var ==
... ...), don't you think so? ;)
If compiler would support special in
Well, DMD accepts this kind of syntax already:
if (value == val1, val2, val3) { }
I think this turns the expression value==val1 into a bool, and then
turns val2 and val3 into bools and compares against each of them. Or
something like that. It's odd and I've never seen it used anywhere.
Maybe we
Well, DMD accepts this kind of syntax already:
if (value == val1, val2, val3) { }
I think this turns the expression value==val1 into a bool, and then
turns val2 and val3 into bools and compares against each of them. Or
something like that. It's odd and I've never seen it used anywhere.
I know it's not doing that, it was a hypothetical. What I'm saying is
I've never seen the comma used this way in code.
I know it's not doing that, it was a hypothetical. What I'm saying is
I've never seen the comma used this way in code.
Well, it would almost certainly be bad practice to do so. The comma operator
can be very useful in some cases (such as for loops) but should generally be
avoided. Here, it's
Andrei Alexandrescu wrote:
On 4/28/11 11:00 AM, Alexander wrote:
On 28.04.2011 17:46, Andrej Mitrovic wrote:
It works, but it makes the if statement ugly again. :)
Well, just a bit - still much better than (var == ... || var = ... ||
var == ... ...), don't you think so? ;)
If
On 28.04.2011 21:46, Timon Gehr wrote:
Why is 'in' not currently defined on arrays? To me it seems like a left-out
that
should be fixed, because it has quite obvious and useful semantics.
+1. It would be very useful and convenient this way, especially if search
will be optimized to series
2011/4/29 Alexander aldem+dm...@nk7.net:
On 28.04.2011 21:46, Timon Gehr wrote:
Why is 'in' not currently defined on arrays? To me it seems like a left-out
that
should be fixed, because it has quite obvious and useful semantics.
+1. It would be very useful and convenient this way,
I often see code written like this:
if (value == somevalue ||
value == someothervalue ||
value == yetanothervalue);
You could use the switch statement. But that introduces indentation,
and is rarely used for a couple of values.
I really like the in keyword, and I also like hashes since
I guess also a hash() for runtime values would be nice, e.g.:
http://codepad.org/a3aCokKT
Andrej Mitrovic:
http://codepad.org/a3aCokKT
Suggestion for the run-time version:
assert(color in hash(red, green, blue));
==
assert(color in set([red, green, blue]));
Bye,
bearophile
34 matches
Mail list logo