faster "stringification"

Orut via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Dec 10 18:09:41 PST 2016


D nub here. I have a Python script that I'd like to implement in 
D. For certain parts, the D equivalent was slower than Python's. 
For example,

Python code:

#dummy code
s = ["abc", "fjkd", "L", "qwa", "r", "uw", "tiro", "bc", "sg", 
"k", "jds", "yd"];

for i in range(10000000):  # a lot of array to string conversions
     '-'.join(s)    # not assigning this to a variable to simplify 
comparison


D code:

import std.stdio;
import std.array;

void main(string[] args){
     string[] s = ["abc", "fjkd", "L", "qwa", "r", "uw", "tiro", 
"bc", "sg", "k", "jds", "yd"];
     for(int i; i<10_000_000; i++) s.join("-"); //see Python 
comments

}

Python was 2x faster.

How should I implement this in D?




More information about the Digitalmars-d-learn mailing list