Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug report: study on lexicals seems broken #4024

Closed
p5pRT opened this issue May 24, 2001 · 7 comments
Closed

Bug report: study on lexicals seems broken #4024

p5pRT opened this issue May 24, 2001 · 7 comments

Comments

@p5pRT
Copy link

p5pRT commented May 24, 2001

Migrated from rt.perl.org#7034 (status was 'resolved')

Searchable as RT7034$

@p5pRT
Copy link
Author

p5pRT commented May 24, 2001

From jacob@sps-c1s2p22.j-e-b.net

'study' on a lexical variable doesn't work as desired.

First benchmark​: with my-variable (with/without study)​:

  with​: 31 wallclock secs (31.19 usr + 0.00 sys = 31.19 CPU) @​ 1.89/s (n=59)
without​: 31 wallclock secs (31.31 usr + 0.00 sys = 31.31 CPU) @​ 2.30/s (n=72)

The version with study runs SLOWER.

Second benchmark​: same code but variable is global​:

  with​: 31 wallclock secs (31.36 usr + 0.00 sys = 31.36 CPU) @​ 3.70/s (n=116)
without​: 32 wallclock secs (31.30 usr + 0.00 sys = 31.30 CPU) @​ 2.30/s (n=72)

The version with study a FASTER (as it should - for 3013 m//'s per study).

In a third benchmark I wanted to study a totally unrelated and nonexistant
global variable and m//atch on a lexical​:

Use of uninitialized value in study at ...

So it looks like study IS studying the lexical (and not some global with the
same name) but m// can NOT use the result.

Forth benchmark​: same code as third but the global was initialized to ''.

  with​: 31 wallclock secs (30.87 usr + 0.00 sys = 30.87 CPU) @​ 1.17/s (n=36)
without​: 30 wallclock secs (30.37 usr + 0.00 sys = 30.37 CPU) @​ 2.30/s (n=70)

?An even bigger slowdown? From studying a variable that only contains an empty
string instead of about 15kb of text? Seems there's more broken...

PS​: This is the benchmarked sub​:

$s1 = undef; $s2 = ''; $html = html-version of Benchmark POD :-);
$x = 'KBGRF'; for my $i (1..1000) { $tags->{$x++} = $x++;
$tags->{$x++ . $i} = $x++ . $i; $tags->{$i . $x++} = $i . $x++; }

sub with {
  my $s = $html; # 1st, 3rd and 4th run
  $s = $html; # 2nd run
  study $s; # 1st and 2nd run
  study $s1; # 3rd run
  study $s2; # 4th run
  foreach my $key (keys %{$tags}) {
  my $a = $key;
  my $b = $tags->{$key};
  $s =~ m/##$a##/;
  $s =~ m/##\?$a##(.*)##\?$a##/;
  $s =~ m/##\!$a##.*##\!$a##/;
  }
  $s =~ m/##.+?##/;
  return $s;
}
"without" is same but misses the 'study' line completely.

PPS​: I thought this were a documentation problem - until the third
benchmark. Maybe it is and I'm just misinterpreting the results...

Perl Info

Flags:
    category=core
    severity=medium

Site configuration information for perl v5.6.1:

Summary of my perl5 (revision 5 version 6 subversion 1) configuration:
  Platform:
    osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread
    uname=''
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=undef
    usethreads=undef use5005threads=undef useithreads=define usemultiplicity=define
    useperlio=undef d_sfio=undef uselargefiles=undef usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
  Compiler:
    cc='cl', ccflags ='-nologo -O1 -MD -DNDEBUG -DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT  -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DPERL_MSVCRT_READFIX',
    optimize='-O1 -MD -DNDEBUG',
    cppflags='-DWIN32'
    ccversion='', gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=4
    alignbytes=8, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='', ldflags ='-nologo -nodefaultlib -release  -libpath:"D:\Perl\lib\CORE"  -machine:x86'
    libpth="D:\Perl\lib\CORE"
    libs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib  comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib msvcrt.lib
    perllibs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib  comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib msvcrt.lib
    libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl56.lib
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -release  -libpath:"D:\Perl\lib\CORE"  -machine:x86'

Locally applied patches:
    ACTIVEPERL_LOCAL_PATCHES_ENTRY


@INC for perl v5.6.1:
    D:/Perl/lib
    D:/Perl/site/lib
    .


Environment for perl v5.6.1:
    HOME (unset)
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=D:\WIN98;D:\WIN98\COMMAND;D:\PROGRA~1\PERL\BIN;D:\RSJCDW95;C:\RSJCDW95;
    PERL_BADLANG (unset)
    SHELL (unset)

@p5pRT
Copy link
Author

p5pRT commented May 24, 2001

From @simoncozens

  You may have only one study active at a time -- if you study a
  different scalar the first is "unstudied".

@p5pRT
Copy link
Author

p5pRT commented May 24, 2001

From [Unknown Contact. See original ticket]

On Fri, May 25, 2001 at 01​:19​:34AM +0200, Michael Jacob wrote​:

study $s;      \# 1st and 2nd run
study $s1;     \# 3rd run
study $s2;     \# 4th run

You may have only one study active at a time -- if you study a
different scalar the first is "unstudied".

He's saying, "on runs 1 and 2, I did 'study $s'. on run 3, I did 'study
$s1'. on run 4, I did 'study $s2'."

@p5pRT
Copy link
Author

p5pRT commented May 24, 2001

From @rspier

He has a function that looks something like this​:

  sub foo {
  study $s;
  study $s1;
  study $s2;

  /regexp/;

  }

And then he's calling that function​:
  foo($s);
  foo($s1);
  ...

So Simon's statement is right. In 'foo', only $s2 is effectively
studied.

-R

Jeff Pinyan writes​:

On May 25, Simon Cozens said​:

On Fri, May 25, 2001 at 01​:19​:34AM +0200, Michael Jacob wrote​:

study $s;      \# 1st and 2nd run
study $s1;     \# 3rd run
study $s2;     \# 4th run

You may have only one study active at a time -- if you study a
different scalar the first is "unstudied".

He's saying, "on runs 1 and 2, I did 'study $s'. on run 3, I did 'study
$s1'. on run 4, I did 'study $s2'."

--
Jeff "japhy" Pinyan japhy@​pobox.com http​://www.pobox.com/~japhy/
Are you a Monk? http​://www.perlmonks.com/ http​://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http​://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
** I need a publisher for my book "Learning Perl's Regular Expressions" **

@p5pRT
Copy link
Author

p5pRT commented May 25, 2001

From @vanstyn

:PS​: This is the benchmarked sub​:

Without the complete code you used for the benchmarking, it is difficult
to work out what is going on, but I cannot reproduce your results here
using perl-5.6.1 under Linux.

These are the results I get with the code below, which show study giving
a definite benefit; I used `perldoc -t Benchmark` for the test since it
should give reasonably consistent output.

Benchmark​: timing 10 iterations
local_none​: 15 wallclock secs (15.13 usr + 0.00 sys = 15.13 CPU) @​ 0.66/s
local_study​: 11 wallclock secs (10.85 usr + 0.00 sys = 10.85 CPU) @​ 0.92/s
  my_none​: 15 wallclock secs (14.99 usr + 0.00 sys = 14.99 CPU) @​ 0.67/s
  my_other​: 15 wallclock secs (15.16 usr + 0.00 sys = 15.16 CPU) @​ 0.66/s
  my_study​: 11 wallclock secs (10.81 usr + 0.00 sys = 10.81 CPU) @​ 0.93/s

Hope this helps,

Hugo


#!/usr/bin/perl -w
$count = shift || 10;
$other = $other = '';
$text = $text = `perldoc -t Benchmark`;
$x = 'KBGRF';
for my $i (1..1000) {
  $tags->{$x++} = $x++;
  $tags->{$x++ . $i} = $x++ . $i;
  $tags->{$i . $x++} = $i . $x++;
}

$run = q{
  foreach my $key (keys %{$tags}) {
  my $a = $key;
  my $b = $tags->{$key};
  $s =~ m/##$a##/;
  $s =~ m/##\?$a##(.*)##\?$a##/;
  $s =~ m/##\!$a##.*##\!$a##/;
  }
  $s =~ m/##.+?##/;
};

use Benchmark;
Benchmark​::timethese($count, {
  my_study => q{ my $s = $text; study $s; } . $run,
  my_none => q{ my $s = $text; } . $run,
  local_study => q{ local $s = $text; study $s; } . $run,
  local_none => q{ local $s = $text; } . $run,
  my_other => q{ my $s = $text; study $other; } . $run,
});

@p5pRT
Copy link
Author

p5pRT commented May 25, 2001

From [Unknown Contact. See original ticket]

On May 25, Simon Cozens said​:

On Fri, May 25, 2001 at 01​:19​:34AM +0200, Michael Jacob wrote​:

study $s;      \# 1st and 2nd run
study $s1;     \# 3rd run
study $s2;     \# 4th run

You may have only one study active at a time -- if you study a
different scalar the first is "unstudied".

He's saying, "on runs 1 and 2, I did 'study $s'. on run 3, I did 'study
$s1'. on run 4, I did 'study $s2'."

You're right. I didn't prepare one test with 8 funktions - I did 4 (ok,
really about 30) tests with 2 funktions that I altered as needed.

so the code was​:

1.a) my $s ... study $s
1.b) my $s ... -
2.a) $s ... study $s
2.b) $s ... -
3.a) my $s ... study $s1
3.b) my $s ... -
4.a) my $s ... study $s2
4.b) my $s ... -

and of cause there was more code around this snippet...

Short summary​:

Speed of m//atch on lexical without study and global without study is same.
m//atch on global with study is faster (as should).
m//atch on lexical with study is slower (as shouldn't)
m//atch on lexical with study on an empty global is even slower.
An study on an undefined global shows that study really study the lexical
when said so.

cu
Michael Jacob

1 similar comment
@p5pRT
Copy link
Author

p5pRT commented May 25, 2001

From [Unknown Contact. See original ticket]

On May 25, Simon Cozens said​:

On Fri, May 25, 2001 at 01​:19​:34AM +0200, Michael Jacob wrote​:

study $s;      \# 1st and 2nd run
study $s1;     \# 3rd run
study $s2;     \# 4th run

You may have only one study active at a time -- if you study a
different scalar the first is "unstudied".

He's saying, "on runs 1 and 2, I did 'study $s'. on run 3, I did 'study
$s1'. on run 4, I did 'study $s2'."

You're right. I didn't prepare one test with 8 funktions - I did 4 (ok,
really about 30) tests with 2 funktions that I altered as needed.

so the code was​:

1.a) my $s ... study $s
1.b) my $s ... -
2.a) $s ... study $s
2.b) $s ... -
3.a) my $s ... study $s1
3.b) my $s ... -
4.a) my $s ... study $s2
4.b) my $s ... -

and of cause there was more code around this snippet...

Short summary​:

Speed of m//atch on lexical without study and global without study is same.
m//atch on global with study is faster (as should).
m//atch on lexical with study is slower (as shouldn't)
m//atch on lexical with study on an empty global is even slower.
An study on an undefined global shows that study really study the lexical
when said so.

cu
Michael Jacob

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant