digitalmars.D - We can see the performance difference from the simple functions in Tango and Phobos
- zsxxsz (68/70) Jul 30 2009 string encode(string s)
- Walter Bright (2/20) Jul 30 2009 That's from std.xml. I won't make any excuse for it, it's very inefficie...
- Jarrett Billingsley (3/5) Jul 30 2009 Uh, who exactly are you trying to convince?
- zsxxsz (6/11) Jul 30 2009 I like D very much, although I'm a C programmer. Phobos, as the stdlib o...
- Andrei Alexandrescu (9/13) Jul 30 2009 That code is terrible, thanks for pointing it out to me. I posted a bug
Hi, below are the functions from Phobos and Tango with the same use, we can see why so many people like Tango more than Phobos.string encode(string s) { // The ifs are (temprarily, we hope) necessary, because // std.string.write.replace // does not do copy-on-write, but instead copies always. if (s.indexOf('&') != -1) s = replace(s,"&","&"); if (s.indexOf('"') != -1) s = replace(s,"\"","""); if (s.indexOf("'") != -1) s = replace(s,"'","'"); if (s.indexOf('<') != -1) s = replace(s,"<","<"); if (s.indexOf('>') != -1) s = replace(s,">",">"); return s; }In Phobos:T[] toEntity(T) (T[] src, T[] dst = null) { T[] entity; auto s = src.ptr; auto t = s; auto e = s + src.length; auto index = 0; while (s < e) switch (*s) { case '"': entity = """; goto common; case '>': entity = ">"; goto common; case '<': entity = "<"; goto common; case '&': entity = "&"; goto common; case '\'': entity = "'"; goto common; common: auto len = s - t; if (dst.length <= index + len + entity.length) dst.length = (dst.length + len + entity.length) + dst.length / 2; dst [index .. index + len] = t [0 .. len]; index += len; dst [index .. index + entity.length] = entity; index += entity.length; t = ++s; break; default: ++s; break; } // did we change anything? if (index) { // copy tail too auto len = e - t; if (dst.length <= index + len) dst.length = index + len; dst [index .. index + len] = t [0 .. len]; return dst [0 .. index + len]; } return src; } We can see the function's performance from Tango is more high than which one from Phobos. This maybe not the only one function difference. :)In Tango:
Jul 30 2009
zsxxsz wrote:Hi, below are the functions from Phobos and Tango with the same use, we can see why so many people like Tango more than Phobos.That's from std.xml. I won't make any excuse for it, it's very inefficient.string encode(string s) { // The ifs are (temprarily, we hope) necessary, because // std.string.write.replace // does not do copy-on-write, but instead copies always. if (s.indexOf('&') != -1) s = replace(s,"&","&"); if (s.indexOf('"') != -1) s = replace(s,"\"","""); if (s.indexOf("'") != -1) s = replace(s,"'","'"); if (s.indexOf('<') != -1) s = replace(s,"<","<"); if (s.indexOf('>') != -1) s = replace(s,">",">"); return s; }In Phobos:
Jul 30 2009
On Thu, Jul 30, 2009 at 9:35 PM, zsxxsz<zhengshuxin hexun.com> wrote:Hi, below are the functions from Phobos and Tango with the same use, we can see why so many people like Tango more than Phobos.Uh, who exactly are you trying to convince? For that matter, what's the point of this thread?
Jul 30 2009
== Quote from Jarrett Billingsley (jarrett.billingsley gmail.com)'s articleOn Thu, Jul 30, 2009 at 9:35 PM, zsxxsz<zhengshuxin hexun.com> wrote:I like D very much, although I'm a C programmer. Phobos, as the stdlib of D, not only have the good code style, but also give the better performance and more good characters. Tango maybe one substitute, but it make us confused there are two basic library exist, if you use one, you can't use the other one, how painful it is. Why can't it be integrated into one? The two libs do have its own good characters.Hi, below are the functions from Phobos and Tango with the same use, we can see why so many people like Tango more than Phobos.Uh, who exactly are you trying to convince? For that matter, what's the point of this thread?
Jul 30 2009
zsxxsz wrote:Hi, below are the functions from Phobos and Tango with the same use, we can see why so many people like Tango more than Phobos.[snip]We can see the function's performance from Tango is more high than which one from Phobos. This maybe not the only one function difference. :)That code is terrible, thanks for pointing it out to me. I posted a bug report on your behalf: http://d.puremagic.com/issues/show_bug.cgi?id=3218 (I'm unhappy with both functions because neither works with on ranges and neither accepts all three character widths.) Any similar findings would be very appreciated. Andrei
Jul 30 2009