On my MacBook, with Raku 2020.01 built on MoarVM version 2020.01.1
changing:
        $ed.data[^$ed.data_size]
to:
        $ed.data.head($ed.data_size)
cut the time in half.

I cannot speak to what might be happening with the Promises.

Test code:
    class Foo {
        has @.data = 0 xx (1024 ** 2);
        has $.data_size = @!data.elems;
    }
    my Foo $ed .= new;

    sub time_it ( Int $type ) {
        for ^3 {
            my Instant $init3 = DateTime.now().Instant;
            for ^10 {
                if $type == 1 {
                    my Blob $bindata = 
Blob[uint8].new($ed.data[^$ed.data_size]);
                }
                else {
                    my Blob $bindata = 
Blob[uint8].new($ed.data.head($ed.data_size));
                }
            }
            say "Bindata in {DateTime.now.Instant - $init3}";
        }
    }
    time_it(1);
    say '';
    time_it(2);
Output:
    Bindata in 8.207297
    Bindata in 8.12964
    Bindata in 8.0798136

    Bindata in 3.434386
    Bindata in 3.4062148
    Bindata in 3.35743893

— 
Hope this helps,
Bruce Gray (Util of PerlMonks)


> On Jun 16, 2020, at 5:17 PM, David Santiago <deman...@gmail.com> wrote:
> 
> Thanks for the answer.
> 
> There's a slight performance improvement, but It still takes more than 1 
> second:
> 
> Code:
> 
> my Instant $init3 = DateTime.now().Instant;
> #my Blob $bindata = Blob[uint8].new(@data);
> my Blob $bindata = Blob[uint8].new($ed.data[^$ed.data_size]);
> say "Bindata in {DateTime.now.Instant - $init3}";
> 
> 
> Bindata in 1.1250962
> 
> 
> :-(
> 
> Curt Tilmes <c...@tilmes.org> escreveu no dia terça, 16/06/2020 à(s) 21:40:
>> 
>> On Tue, Jun 16, 2020 at 5:18 PM David Santiago <deman...@gmail.com> wrote:
>>> my uint8 @data = $ed.data[0..$ed.data_size-1].Array;
>>> my Blob $bindata = Blob[uint8].new(@data);
>> 
>> Not absolutely sure, but it seems like you are copying the data twice.
>> Try just
>> 
>> my $bindata = Blob.new($ed.data[^$ed.data_size]);

Reply via email to