develooper Front page | perl.perl5.porters | Postings from August 2013

[perl #117355] [lu]cfirst don't respect 'use bytes'

Thread Previous | Thread Next
From:
Victor Efimov via RT
Date:
August 12, 2013 20:08
Subject:
[perl #117355] [lu]cfirst don't respect 'use bytes'
Message ID:
rt-3.6.HEAD-2552-1376338120-229.117355-15-0@perl.org
On Sun Aug 11 19:56:53 2013, rjbs wrote:
> I haven't given this a lot of thought, but I think that if we can make
> bytes.pm ejectable, we
> should do so.  It's okay if it gets slower, since we've been telling
> people for years that it's only a
> debugging tool, if that.
> 
> Thoughts? Objections?


Possible use bytes to speedup regexps by 20-40% at some cases:

use warnings;
use strict;
use utf8;
use bytes ();
use Encode;
use Benchmark qw/:all/;

sub test
{
  my ($s) = @_;
  $s = ($s x 400)."z";
  $s =~ /z/ for (1..100);
}

sub try_drop_utf8_flag
{
  Encode::_utf8_off($_[0]) if utf8::is_utf8($_[0]) &&
(bytes::length($_[0]) == length($_[0]));
}

my $ascii = "x";
my ($ascii_u, undef) = split(/ /, "x ั‚ะตัั‚");

die unless $ascii_u eq $ascii;

cmpthese(-1,{
  'ascii' => sub { test($ascii); },
  'ascii with utf8 on' => sub { test($ascii_u);},
  'ascii with utf8 bit cleared' => sub {
    my $s = $ascii_u;
    try_drop_utf8_flag($s);
    die if utf8::is_utf8($s);
    test($s);
   },
});

__END__

perl-5.18.0
==========
                               Rate ascii with utf8 on ascii with utf8
bit cleared ascii
ascii with utf8 on          22635/s                 --                 
      -27%  -28%
ascii with utf8 bit cleared 30919/s                37%                 
        --   -2%
ascii                       31508/s                39%                 
        2%    --

perl-5.10.0
==========
                               Rate ascii with utf8 on ascii with utf8
bit cleared ascii
ascii with utf8 on          25831/s                 --                 
      -19%  -21%
ascii with utf8 bit cleared 31717/s                23%                 
        --   -4%
ascii                       32881/s                27%                 
        4%    --


---
via perlbug:  queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=117355

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About