Utf8 to Utf32 cast cost

Daniel Kozák via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jun 8 04:44:33 PDT 2015


On Mon, 08 Jun 2015 11:32:07 +0000
Kagamin via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com>
wrote:

> On Monday, 8 June 2015 at 10:59:45 UTC, Daniel Kozák wrote:
> > import std.conv;
> > import std.utf;
> > import std.datetime;
> > import std.stdio;
> >
> > void f0() {
> >     string somestr = "some not so long utf8 string 
> > forbenchmarking";
> >     dstring str = to!dstring(somestr);
> > }
> >
> >
> > void f1() {
> >     string somestr = "some not so long utf8 string 
> > forbenchmarking";
> >     dstring str = toUTF32(somestr);
> > }
> >
> > void main() {
> >     auto r = benchmark!(f0,f1)(1_000_000);
> >     auto f0Result = to!Duration(r[0]);
> >     auto f1Result = to!Duration(r[1]);
> >     writeln("f0 time: ",f0Result);
> >     writeln("f1 time: ",f1Result);
> > }
> >
> >
> > /// output ///
> > f0 time: 2 secs, 281 ms, 933 μs, and 8 hnsecs
> > f1 time: 600 ms, 979 μs, and 8 hnsecs
> 
> Chances are you're benchmarking the GC. Try 
> benchmark!(f0,f1,f0,f1,f0,f1);

No difference even with GC.disable() results are same.



More information about the Digitalmars-d-learn mailing list