On Wed, 27 May 2015 05:48:11 +0000 zhmt via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com> wrote:
> I am writing a echoclient, as below: > > Ptr!Conn conn = connect("127.0.0.1",8881); > ubyte[100] buf; > for(int i=0; i<N; i++) > { > scope string str = format("%s",i); > conn.write((cast(ubyte*)str.ptr)[0..str.length]); > conn.read(buf[0..str.length]); > n++; > } > conn.close(); > > > When it loops about more than 100000 times,the throughput will > fall from 60000request/second to 26request/second. > > If the code changes a little as below: > > scope string str = format("%s",10000); //changes to a constant > > It will runs normally with speed of 60000request/second. I test > for 13minutes, everything seems well. > > > > What happened when the code changes a little? Who will give an > explaination,Thanks a lot? what happend if you use sformat instead? Ptr!Conn conn = connect("127.0.0.1",8881); ubyte[100] buf; char[100] buf2; for(int i=0; i<N; i++) { auto str = sformat(buf2, "%s",i); conn.write((cast(ubyte*)str.ptr)[0..str.length]); conn.read(buf[0..str.length]); n++; } conn.close();