Skip Menu |

This queue is for tickets about the MIME-Base64 CPAN distribution.

Report information
The Basics
Id: 62404
Status: resolved
Priority: 0/
Queue: MIME-Base64

People
Owner: Nobody in particular
Requestors: MARKOV [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: length of base64 encoded
In my XML::Compile, I have to check the length of a base64Binary data-type which Base64 in encoded form. For reasons of performance, I do not want to decode the data, nor want to count the base64 characters in pure Perl. Would it be possible to add a function to your module which can report the length of an encoded base64 string without decoding it first?
On Sat Oct 23 17:39:54 2010, MARKOV wrote: Show quoted text
> In my XML::Compile, I have to check the length of a base64Binary > data-type which Base64 in encoded form. For reasons of performance, I do > not want to decode the data, nor want to count the base64 characters in > pure Perl. > > Would it be possible to add a function to your module which can report > the length of an encoded base64 string without decoding it first?
Sure. Do you need a length that includes the newline chars injected to break the base64 string broken into lines? BTW, the length of the encoded chars without the newlines is: $b64_len = int((length($str) + 2) / 3) * 4;
Subject: Re: [rt.cpan.org #62404] length of base64 encoded
Date: Sun, 24 Oct 2010 21:01:27 +0200
To: Gisle_Aas via RT <bug-MIME-Base64 [...] rt.cpan.org>
From: Mark Overmeer <mark [...] overmeer.net>
* Gisle_Aas via RT (bug-MIME-Base64@rt.cpan.org) [101024 07:50]: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=62404 >
> > Would it be possible to add a function to your module which can report > > the length of an encoded base64 string without decoding it first?
> > Sure. Do you need a length that includes the newline chars injected > to break the base64 string broken into lines?
That would simply be standard length() Show quoted text
> > BTW, the length of the encoded chars without the newlines is: > $b64_len = int((length($str) + 2) / 3) * 4;
I would like the size of the decoded string, without actually decoding it. The calculation in Perl is expensive because counting the white-spaces is expensive. What I have now is: my $enc = $$ref =~ tr/A-Za-z0-9+=//; ($enc >> 2) * 3 - ($$ref =~ tr/=//); (passing a ref to avoid a copy of a sometimes huge string...) -- Regards, MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions Mark@Overmeer.net solutions@overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net
I misunderstood and thought you would like to know the encoded length. I now have an implementation of the decoded length at <http://github.com/gisle/mime- base64/commit/806364aac93e14dbb307576bcda461e14598e029>. Does this make a difference performance wise for you application?
Subject: Re: [rt.cpan.org #62404] length of base64 encoded
Date: Mon, 25 Oct 2010 22:11:17 +0200
To: Gisle_Aas via RT <bug-MIME-Base64 [...] rt.cpan.org>
From: Mark Overmeer <mark [...] overmeer.net>
* Gisle_Aas via RT (bug-MIME-Base64@rt.cpan.org) [101025 19:02]: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=62404 > > > I misunderstood and thought you would like to know the encoded length. > I now have an implementation of the decoded length at > <http://github.com/gisle/mime-base64/commit/806364aac93e14dbb307576bcda461e14598e029>.
Weird that I get an 3.08 version from git, where the latest release was 3.09. I already expected that implementation would be short. Still, your speed astoun me ;-) ChangeLog and @EXPORT still missing. Show quoted text
> Does this make a difference performance wise for you application?
My benchmark script: #!/usr/bin/perl use warnings; use strict; use blib; use Benchmark; use MIME::Base64; use File::Slurp; my $bin = read_file '/tmp/a.jpg'; # image of 50k my $b64 = encode_base64 $bin; timethese ( 3000 , { XS => sub { MIME::Base64::decoded_base64_length($b64) } , Perl => sub { my $enc = $b64 =~ tr/A-Za-z0-9+=//; ($enc >> 2) * 3 - ($b64 =~ tr/=//); } } ); Guess what: Perl: 8 wallclock secs (7.11 usr +0.00 sys = 7.11 CPU) @ 421.94/s (n=3000) XS: 8 wallclock secs (8.41 usr +0.01 sys = 8.42 CPU) @ 356.29/s (n=3000) Your XS version is slower! No idea why. -- Regards, MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions Mark@Overmeer.net solutions@overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net
On Mon Oct 25 16:11:29 2010, Mark@Overmeer.net wrote: Show quoted text
> * Gisle_Aas via RT (bug-MIME-Base64@rt.cpan.org) [101025 19:02]:
> > <URL: https://rt.cpan.org/Ticket/Display.html?id=62404 > > > > > I misunderstood and thought you would like to know the encoded
> length.
> > I now have an implementation of the decoded length at > > <http://github.com/gisle/mime-
> base64/commit/806364aac93e14dbb307576bcda461e14598e029>. > > Weird that I get an 3.08 version from git, where the latest release > was 3.09.
The 3.09 release wasn't tagged. Fixed now. Show quoted text
> Guess what: > Perl: 8 wallclock secs (7.11 usr +0.00 sys = 7.11 CPU) @ 421.94/s > (n=3000) > XS: 8 wallclock secs (8.41 usr +0.01 sys = 8.42 CPU) @ 356.29/s > (n=3000) > > Your XS version is slower! No idea why.
On my Mac laptop I get: Benchmark: timing 30000 iterations of Perl, XS... Perl: 6 wallclock secs ( 5.95 usr + 0.01 sys = 5.96 CPU) @ 5033.56/s (n=30000) XS: 2 wallclock secs ( 2.09 usr + 0.01 sys = 2.10 CPU) @ 14285.71/s (n=30000)
Subject: Re: [rt.cpan.org #62404] length of base64 encoded
Date: Tue, 26 Oct 2010 13:01:38 +0200
To: Gisle_Aas via RT <bug-MIME-Base64 [...] rt.cpan.org>
From: Mark Overmeer <solutions [...] overmeer.net>
* Gisle_Aas via RT (bug-MIME-Base64@rt.cpan.org) [101025 23:12]: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=62404 >
> > Guess what: > > Perl: 8 wallclock secs (7.11 usr +0.00 sys = 7.11 CPU) @ 421.94/s > > XS: 8 wallclock secs (8.41 usr +0.01 sys = 8.42 CPU) @ 356.29/s > > Your XS version is slower! No idea why.
> > On my Mac laptop I get: > Benchmark: timing 30000 iterations of Perl, XS... > Perl: 6 wallclock secs ( 5.95 usr + 0.01 sys = 5.96 CPU) @ 5033.56/s > XS: 2 wallclock secs ( 2.09 usr + 0.01 sys = 2.10 CPU) @ 14285.71/s
It seems that the XS implementation is much faster on older Perl versions. On my two perl 5.12.1 instances, they are about the same speed (XS often a little slower)... while on Perl 5.8.7, the XS version is three times as fast. I will use your implementation in any case, because it simplifies my code ;-) -- Thanks! MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions Mark@Overmeer.net solutions@overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net
MIME-Base64-3.10 has been uploaded to CPAN.