develooper Front page | perl.perl6.users | Postings from June 2020

Help converting CArray[uint8] to Blob

Thread Next
David Santiago
June 16, 2020 21:18
Help converting CArray[uint8] to Blob
Message ID:

Can i get some help in trying to improve the performance of the
following snippet?

The following code runs inside a react block that it's waiting for
channel values.

The promise $yenc_promise returns a CStruct with a CArray[uint] $data
and a uint8 $data_size.

my Instant $init =;
my Data $ed = await $yenc_promise;
say "Wating for promise in { - $init}";
my Instant $init2 =;
my uint8 @data = $[0..$ed.data_size-1].Array;
say "extracting in { - $init2}";
my Instant $init3 =;
my Blob $bindata = Blob[uint8].new(@data);
say "Bindata in { - $init3}";
say "Total = {$init}";

So basically i'm extracting the CArray from the struct and then
converting it to a blob (so i can pass it to socket's write function)

When i run that code i get the following times:

Wating for promise in 0.000409156
extracting in 1.5681954
Bindata in 0.1248611
Total = 1.760531992

How can I improve that piece of code so it will take less than 1
second (against the 1.5 plus secs)?

And why if I put more promises running that same code, it gets way
slower? For example with five promises:

Wating for promise in 0.0003156
Wating for promise in 0.000339
Wating for promise in 0.0003339
Wating for promise in 0.000343
Wating for promise in 0.0003477
extracting in 3.2270008
extracting in 3.4507399
Bindata in 0.4428602
Total = 3.6717681
Bindata in 0.2877211
Total = 3.7541319
extracting in 3.88532646
extracting in 3.72995056
extracting in 3.90478574
Bindata in 0.16822032
Total = 4.0554652
Bindata in 0.15585004
Total = 3.90223033

Best regards,
David Santiago

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About