Re: Need way to compare classes, and primitive types in bst Template

2017-06-09 Thread Mark via Digitalmars-d-learn
Ok. WOW! I was way off. I adapted your code to my BST and it works perfectly. Thanks! I didn't know what static if was. I should experiment with it. For the code that I mentioned, I'd have to retype it. I wrote, tried and deleted those pieces of code several days ago because it really didn

Re: D for Web Development?

2017-06-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 9 June 2017 at 22:01:14 UTC, Michael Reiland wrote: So if I'm understanding this code correctly, your libs don't have any sort of routing setup either, and I would have to write the code to inspect the URL and do the right thing? web.d does (it is automatic via names in the source c

Re: Is D slow?

2017-06-09 Thread Ali Çehreli via Digitalmars-d-learn
On 06/09/2017 03:46 PM, Honey wrote: > On Friday, 9 June 2017 at 20:27:58 UTC, Ali Çehreli wrote: >> On 06/09/2017 12:29 PM, Honey wrote: >> >> > I think, I should not rely on standard library facilities. >> >> I think you hit a Phobos function with particularly bad performance >> (which can be im

Re: a way to specily floating-point numbers as bit patters

2017-06-09 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 9 June 2017 at 16:56:46 UTC, ketmar wrote: Petar Kirov [ZombineDev] wrote: Do HexFloats (http://dlang.org/spec/lex#HexFloat) help? hm. i somehow completely missed "%a" format specifier! yeah, "-0x1.6ep-3" did the trick. tnx. i should do my homework *before* posting big rants

Re: Is D slow?

2017-06-09 Thread Honey via Digitalmars-d-learn
On Friday, 9 June 2017 at 20:27:58 UTC, Ali Çehreli wrote: On 06/09/2017 12:29 PM, Honey wrote: > I think, I should not rely on standard library facilities. I think you hit a Phobos function with particularly bad performance (which can be improved). Phobos is not a slow library in general.

Re: Is D slow?

2017-06-09 Thread Honey via Digitalmars-d-learn
On Friday, 9 June 2017 at 21:11:50 UTC, Steven Schveighoffer wrote: Just to show you what I meant, I changed your code to eliminate the functors completely, the main function now looks like this: foreach (i; 0 .. N) { insertionSort!((a, b) => lt(a, b))(v); insertionSor

Re: D for Web Development?

2017-06-09 Thread Michael Reiland via Digitalmars-d-learn
On Friday, 9 June 2017 at 15:07:03 UTC, Adam D. Ruppe wrote: // compile with the cgi.d, database.d, postgres.d, and dom.d library modules // and make sure your C libpq library is available. so on my computer, the // compile command is: // dmd webtest.d ~/arsd/{cgi,database,postgres,dom} -L-L/

Re: Is D slow?

2017-06-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/9/17 3:29 PM, Honey wrote: On Friday, 9 June 2017 at 18:32:06 UTC, Steven Schveighoffer wrote: Wow, so that's how D code would look like if it were C++ :) Well, I cannot (and did not try to) hide where I am coming from. ;-) hehe this was meant more as a dig at C++ syntax and not you, I

Re: Is D slow?

2017-06-09 Thread Ali Çehreli via Digitalmars-d-learn
On 06/09/2017 12:29 PM, Honey wrote: > I think, I should not rely on standard library facilities. I think you hit a Phobos function with particularly bad performance (which can be improved). Phobos is not a slow library in general. Ali

Re: Is D slow?

2017-06-09 Thread Laeeth Isharc via Digitalmars-d-learn
On Friday, 9 June 2017 at 19:29:35 UTC, Honey wrote: On Friday, 9 June 2017 at 18:32:06 UTC, Steven Schveighoffer wrote: Wow, so that's how D code would look like if it were C++ :) Well, I cannot (and did not try to) hide where I am coming from. ;-) The results are quite disappointing. Wha

Re: Is D slow?

2017-06-09 Thread Era Scarecrow via Digitalmars-d-learn
On Friday, 9 June 2017 at 18:32:06 UTC, Steven Schveighoffer wrote: Wow, so that's how D code would look like if it were C++ :) When dipping my toes into C++ to do a quicksort algorithm, I quickly got annoyed I'd have to create all the individual comparison functions rather than just one lik

Re: Is D slow?

2017-06-09 Thread Honey via Digitalmars-d-learn
On Friday, 9 June 2017 at 19:29:35 UTC, Honey wrote: Unfortunately, that does not increase my confidence. I should add that, nevertheless, I very much appreciate and respect D and its community. Great work! :-)

Re: Is D slow?

2017-06-09 Thread Honey via Digitalmars-d-learn
On Friday, 9 June 2017 at 18:32:06 UTC, Steven Schveighoffer wrote: Wow, so that's how D code would look like if it were C++ :) Well, I cannot (and did not try to) hide where I am coming from. ;-) The results are quite disappointing. What seems particularly strange to me is that -boundsch

Re: Is D slow?

2017-06-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/9/17 2:32 PM, Steven Schveighoffer wrote: In answer to the subject, no D is not slow. However, it's quite possible that std.algorithm.bringToFront is slower than std::rotate, or SortedRange.upperBound is slower than std::upper_bound, or both. I don't think it's a design issue per se, probab

Re: Is D slow?

2017-06-09 Thread Ali Çehreli via Digitalmars-d-learn
On 06/09/2017 11:32 AM, Steven Schveighoffer wrote: > In answer to the subject, no D is not slow. However, it's quite possible > that std.algorithm.bringToFront is slower than std::rotate, or > SortedRange.upperBound is slower than std::upper_bound, or both. That was exactly my conclusion. I fou

Re: Is D slow?

2017-06-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/9/17 12:21 PM, Honey wrote: Hi guys, I wrote a toy benchmark in C++ [1] and tried to literally translate it to D [2]. Wow, so that's how D code would look like if it were C++ :) The results are quite disappointing. What seems particularly strange to me is that -boundscheck=off leads to

Re: How to implement opCmp?

2017-06-09 Thread Honey via Digitalmars-d-learn
On Friday, 9 June 2017 at 17:28:18 UTC, Steven Schveighoffer wrote: This is why I think such a function should exist in Phobos/druntime. I'm not 100% sure it doesn't already, but I couldn't find one... Looking at the implementation of Tuple.opCmp, I'm not sure I'd bet on existence of opCmp fo

Re: a way to specily floating-point numbers as bit patters

2017-06-09 Thread Honey via Digitalmars-d-learn
On Friday, 9 June 2017 at 17:25:22 UTC, ketmar wrote: it is highly platform-dependent. and both bin->dec, and dec->bin conversion routines can contain errors, btw. so using decimal forms for exact bit-patterns is the last thing i want to do, as i know how fragile they are. Sure. Hex-format is

Re: a way to specily floating-point numbers as bit patters

2017-06-09 Thread ketmar via Digitalmars-d-learn
Honey wrote: On Friday, 9 June 2017 at 16:34:28 UTC, ketmar wrote: Try -0.1685f. it doesn't matter if i can find the decimal representation for the given bit pattern or not. the whole post is about removing the need to rely on lossy binary->decimal->binary conversions. Lossless turn-a

Re: How to implement opCmp?

2017-06-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/9/17 11:33 AM, Honey wrote: Hi Steve! On Friday, 9 June 2017 at 15:12:42 UTC, Steven Schveighoffer wrote: If I were to write it, it would be something like: int doCmp(T)(auto ref T t1, auto ref T t2) { static if(is(typeof(t1.opCmp(t2 return t1.opCmp(t2); else { if(t

Re: a way to specily floating-point numbers as bit patters

2017-06-09 Thread ketmar via Digitalmars-d-learn
Basile B. wrote: On Friday, 9 June 2017 at 17:18:43 UTC, ketmar wrote: Basile B. wrote: enum binFloat = *cast(float*) &b; i was SO sure that this won't work in CTFE that i didn't even tried to do it. "it will fail anyway, there is no reason in trying!" ;-) You can do the arithmetic

Re: a way to specily floating-point numbers as bit patters

2017-06-09 Thread Basile B. via Digitalmars-d-learn
On Friday, 9 June 2017 at 17:18:43 UTC, ketmar wrote: Basile B. wrote: enum binFloat = *cast(float*) &b; i was SO sure that this won't work in CTFE that i didn't even tried to do it. "it will fail anyway, there is no reason in trying!" ;-) You can do the arithmetic as well. I don't k

Re: a way to specily floating-point numbers as bit patters

2017-06-09 Thread ketmar via Digitalmars-d-learn
Basile B. wrote: enum binFloat = *cast(float*) &b; i was SO sure that this won't work in CTFE that i didn't even tried to do it. "it will fail anyway, there is no reason in trying!" ;-)

Re: a way to specily floating-point numbers as bit patters

2017-06-09 Thread Basile B. via Digitalmars-d-learn
On Friday, 9 June 2017 at 16:42:31 UTC, ketmar wrote: Basile B. wrote: Yes, easy to do, a template alà octal or hexString. can you show it, please? remember, CTFE-able! Sure, here's a dirty draft: template binFloat(string sign, string exp, string mant) { enum s = sign == "+" ? "0" : "1"

Re: Can I speed up this log parsing script further?

2017-06-09 Thread Daniel Kozak via Digitalmars-d-learn
btw it is important to use right compiler with right flags I am using ldc with this flags ldmd2 -O -release -boundscheck=off On Fri, Jun 9, 2017 at 6:28 PM, uncorroded via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Friday, 9 June 2017 at 14:19:48 UTC, Daniel Kozak wrote:

Re: a way to specily floating-point numbers as bit patters

2017-06-09 Thread ketmar via Digitalmars-d-learn
Petar Kirov [ZombineDev] wrote: Do HexFloats (http://dlang.org/spec/lex#HexFloat) help? hm. i somehow completely missed "%a" format specifier! yeah, "-0x1.6ep-3" did the trick. tnx. i should do my homework *before* posting big rants, lol.

Re: a way to specily floating-point numbers as bit patters

2017-06-09 Thread Honey via Digitalmars-d-learn
On Friday, 9 June 2017 at 16:41:01 UTC, Honey wrote: Lossless turn-around is guaranteed if you are using sufficiently many digits. In case of IEEE-754 single precision it's 8 significant decimal digits. s/turn-around/recovery/g s/8/9/g :-P

Re: Can I speed up this log parsing script further?

2017-06-09 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 09, 2017 at 04:28:08PM +, uncorroded via Digitalmars-d-learn wrote: [...] > Is there a good resource to read about the good stuff in std.algorithm > and range? I tried going through the library docs but they are too > exhaustive! [...] Try these: http://ddili.org/ders/d.e

Re: a way to specily floating-point numbers as bit patters

2017-06-09 Thread via Digitalmars-d-learn
On Friday, 9 June 2017 at 16:07:36 UTC, ketmar wrote: let's say that i have precomputed some `float`-typed tables, and now i want to use 'em in my code. for example, a table for Lagrange series. the table itself is like 10 numbers, but the code calculating it rather big, and it depends of archi

Re: a way to specily floating-point numbers as bit patters

2017-06-09 Thread ketmar via Digitalmars-d-learn
Basile B. wrote: ps. "-0.17 0xBE2AAAC1". it's not the same! (and yes, it matters). -0.17f is not representable as a 32 bit float. The actuall value that's stored is -0.169994592259765625, hence the difference. See https://www.h-schmidt.net/FloatConverter/IEEE754.html and

Re: a way to specily floating-point numbers as bit patters

2017-06-09 Thread Honey via Digitalmars-d-learn
On Friday, 9 June 2017 at 16:34:28 UTC, ketmar wrote: Try -0.1685f. it doesn't matter if i can find the decimal representation for the given bit pattern or not. the whole post is about removing the need to rely on lossy binary->decimal->binary conversions. Lossless turn-around is guaran

Re: a way to specily floating-point numbers as bit patters

2017-06-09 Thread Basile B. via Digitalmars-d-learn
On Friday, 9 June 2017 at 16:07:36 UTC, ketmar wrote: let's say that i have precomputed some `float`-typed tables, and now i want to use 'em in my code. for example, a table for Lagrange series. the table itself is like 10 numbers, but the code calculating it rather big, and it depends of archi

Re: a way to specily floating-point numbers as bit patters

2017-06-09 Thread ketmar via Digitalmars-d-learn
Honey wrote: On Friday, 9 June 2017 at 16:07:36 UTC, ketmar wrote: one of my calculated values is `-0.17`, which has bit-pattern of 0xBE2AAAB7. now, let's say i want to use this number in my code: float v = -0.17f; writefln("%f 0x%08X", v, *cast(uint*)&v); ps. "-0

Re: Can I speed up this log parsing script further?

2017-06-09 Thread uncorroded via Digitalmars-d-learn
On Friday, 9 June 2017 at 14:19:48 UTC, Daniel Kozak wrote: import std.stdio; import std.array: appender, array; import std.algorithm : findSplit, splitter, joiner, canFind, map; import std.typecons : tuple, Tuple; import std.conv : to; import std.range : dropOne, dropExactly, takeExactly, chai

Re: a way to specily floating-point numbers as bit patters

2017-06-09 Thread Honey via Digitalmars-d-learn
On Friday, 9 June 2017 at 16:07:36 UTC, ketmar wrote: one of my calculated values is `-0.17`, which has bit-pattern of 0xBE2AAAB7. now, let's say i want to use this number in my code: float v = -0.17f; writefln("%f 0x%08X", v, *cast(uint*)&v); ps. "-0.17 0xBE2AA

Is D slow?

2017-06-09 Thread Honey via Digitalmars-d-learn
Hi guys, I wrote a toy benchmark in C++ [1] and tried to literally translate it to D [2]. The results are quite disappointing. What seems particularly strange to me is that -boundscheck=off leads to a performance decrease. Am I missing anything? // $ clang++ -std=c++1z -O3 cmp-bench.cpp /

a way to specily floating-point numbers as bit patters

2017-06-09 Thread ketmar via Digitalmars-d-learn
let's say that i have precomputed some `float`-typed tables, and now i want to use 'em in my code. for example, a table for Lagrange series. the table itself is like 10 numbers, but the code calculating it rather big, and it depends of architecture (so it can yield different results on different

Re: How to implement opCmp?

2017-06-09 Thread drug via Digitalmars-d-learn
I re-read thoroughly and got it)

Re: How to implement opCmp?

2017-06-09 Thread drug via Digitalmars-d-learn
09.06.2017 18:12, Steven Schveighoffer пишет: int doCmp(T)(auto ref T t1, auto ref T t2) { static if(is(typeof(t1.opCmp(t2 return t1.opCmp(t2); else { if(t1 < t2) return -1; else if(t1 > t2) return 1; return 0; } } Isn't it enough to use just '<' et

Re: How to implement opCmp?

2017-06-09 Thread Honey via Digitalmars-d-learn
Hi Steve! On Friday, 9 June 2017 at 15:12:42 UTC, Steven Schveighoffer wrote: TypeInfo can provide the comparison for you, but it's a little ugly. If we take a look at std.algorithm.comparison.cmp, it uses operators to compare two values (i.e. < first, then >, otherwise return 0). However,

Re: How to implement opCmp?

2017-06-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/9/17 10:53 AM, Honey wrote: Hi everyone! Given struct Pair(T, U = T) { T f; U s; } what is the intended way to genrically implement opCmp for this struct? The naive approach struct Pair(T, U = T) { // [...] int opCmp(const Pair r) const { immutable c = f.opCmp(r.f); r

Re: Need way to compare classes, and primitive types in bst Template

2017-06-09 Thread ag0aep6g via Digitalmars-d-learn
On 06/09/2017 04:08 PM, Mark wrote: Possibly. but I can't use those methods on primitive types. Those methods implement operators. In your code you use the usual comparison operators: '==', '<', etc. Also, I tried implementing a internal method to determine if it is a class, or primitive,

Re: D for Web Development?

2017-06-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 9 June 2017 at 08:20:34 UTC, Michael Reiland wrote: I'm definitely interested, a small example with the integrated httpd would be great. Just a hello world would be perfect. Here's one: --- // compile with the cgi.d, database.d, postgres.d, and dom.d library modules // and make

How to implement opCmp?

2017-06-09 Thread Honey via Digitalmars-d-learn
Hi everyone! Given struct Pair(T, U = T) { T f; U s; } what is the intended way to genrically implement opCmp for this struct? The naive approach struct Pair(T, U = T) { // [...] int opCmp(const Pair r) const { immutable c = f.opCmp(r.f); return c != 0 ? c : s.opCmp(r.s);

Re: Can I speed up this log parsing script further?

2017-06-09 Thread Daniel Kozak via Digitalmars-d-learn
import std.stdio; import std.array: appender, array; import std.algorithm : findSplit, splitter, joiner, canFind, map; import std.typecons : tuple, Tuple; import std.conv : to; import std.range : dropOne, dropExactly, takeExactly, chain; alias push_type = Tuple!(int, char[], int, bool, bool); alia

Re: Need way to compare classes, and primitive types in bst Template

2017-06-09 Thread Mark via Digitalmars-d-learn
On Friday, 9 June 2017 at 05:53:11 UTC, ag0aep6g wrote: ... Get rid of `real val;` and just compare `payload`s. For classes, you can detect them with `static if (is(T == class))` or some such, and cast to void* when comparing. But when you cast to void*, you're ignoring an opEquals or opCmp t

Re: D for Web Development?

2017-06-09 Thread Wulfklaue via Digitalmars-d-learn
On Friday, 9 June 2017 at 08:20:34 UTC, Michael Reiland wrote: Thanks for the link to those resources, that'll definitely help giving me a broad overview, which for me is best. If I know something is there I can dive into the details when it becomes more important to what I'm doing. I'm defi

Re: D for Web Development?

2017-06-09 Thread Wulfklaue via Digitalmars-d-learn
On Thursday, 8 June 2017 at 07:32:44 UTC, Michael Reiland wrote: Hey guys, I'm looking for a web solution that's: 1. Supported on Linux First tier: D, Rust, Go, .netCore Second tier: Nim, Crystal, ... plenty of choices :) Not advised for Linux: Swift... Unless you go for a pure Swift framew

Re: Can I speed up this log parsing script further?

2017-06-09 Thread uncorroded via Digitalmars-d-learn
On Friday, 9 June 2017 at 08:58:38 UTC, Daniel Kozak wrote: There is no difference in speed because you do not process your data lazily, so you make many allocations, so this is main reason why it is so slow. I could improve that, but I will need to see some example data, which you are trying

Re: Can I speed up this log parsing script further?

2017-06-09 Thread Daniel Kozak via Digitalmars-d-learn
On Fri, Jun 9, 2017 at 9:34 AM, uncorroded via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > Hi guys, > > I am a beginner in D. As a project, I converted a log-parsing script in > Python which we use at work, to D. This link was helpful - ( > https://dlang.org/blog/2017/05/24/f

Re: Can I speed up this log parsing script further?

2017-06-09 Thread Daniel Kozak via Digitalmars-d-learn
Dne 9.6.2017 v 09:50 rikki cattermole via Digitalmars-d-learn napsal(a): On 09/06/2017 8:34 AM, uncorroded wrote: Hi guys, ... The code isn't entirely 1:1. Any usage of IO (includes stdout via writeln) is expensive. Your python code doesn't write anything to stdout (or perform any calls).

Re: D for Web Development?

2017-06-09 Thread Michael Reiland via Digitalmars-d-learn
Thanks for the link to those resources, that'll definitely help giving me a broad overview, which for me is best. If I know something is there I can dive into the details when it becomes more important to what I'm doing. On Friday, 9 June 2017 at 03:34:20 UTC, Adam D. Ruppe wrote: anyway, if

Re: Can I speed up this log parsing script further?

2017-06-09 Thread Daniel Kozak via Digitalmars-d-learn
I would considered using appender for pushed and npushed. Can you post file on which you are running benchmarking? On Fri, Jun 9, 2017 at 9:50 AM, rikki cattermole via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On 09/06/2017 8:34 AM, uncorroded wrote: > >> Hi guys, >> >> I

Re: Can I speed up this log parsing script further?

2017-06-09 Thread rikki cattermole via Digitalmars-d-learn
On 09/06/2017 8:34 AM, uncorroded wrote: Hi guys, I am a beginner in D. As a project, I converted a log-parsing script in Python which we use at work, to D. This link was helpful - ( https://dlang.org/blog/2017/05/24/faster-command-line-tools-in-d/ ) I compiled it with dmd and ldc. The log fi

Can I speed up this log parsing script further?

2017-06-09 Thread uncorroded via Digitalmars-d-learn
Hi guys, I am a beginner in D. As a project, I converted a log-parsing script in Python which we use at work, to D. This link was helpful - ( https://dlang.org/blog/2017/05/24/faster-command-line-tools-in-d/ ) I compiled it with dmd and ldc. The log file is 52 MB. With dmd (not release build

Re: DMD [-O flag] vs. [memory allocation in a synchronized class]

2017-06-09 Thread realhet via Digitalmars-d-learn
On Thursday, 8 June 2017 at 17:39:41 UTC, Ivan Kazmenko wrote: Reported: https://issues.dlang.org/show_bug.cgi?id=17481 Thank You!