Two points:
  1. A tiny change should save you big time. Instead of doing the exponential stuff of 256 every time, you should use a variable to store the current value of 256 ** k from each iteration, and next iteration just multiply it by 256, to get 256 ** (k + 1), see the code.

    Now the complexity is a linear function of your array size, ~ o(n).

  2. After my code change, you don't need a $count any more, but I still want to mention that there is absolutely no need to use BigInt for $count, that's really really huge, is your number that HUGE?
Be careful, pack and unpack does not fit in the picture.
sub bytearray_to_bigint { my @array = @_; my $base = Math::BigInt->new('1'); my $result = Math::BigInt->new('0'); foreach my $a (@array) { $result += $a * $base; $base *= 256; } return $result; }

In reply to Re: Converting an array of bytes into a BigInt - speed considerations by pg
in thread Converting an array of bytes into a BigInt - speed considerations by dempa

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.