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

"42 < $a < 666" should be faster than "42 < $a && $a < 666", but is 2x as slow #1368

Closed
lizmat opened this issue Jan 5, 2018 · 1 comment
Assignees

Comments

@lizmat
Copy link
Contributor

lizmat commented Jan 5, 2018

The Problem

"42 < $a < 666" should be faster than "42 < $a && $a < 666", but is 2x as slow

Expected Behavior

42 < $a < 666 should be faster

Actual Behavior

42 < $a < 666 is twice as slow

Steps to Reproduce

m: my $a = 42; for ^1000000 { my $b = 42 < $a < 666 }; say now - INIT now
<+camelia> rakudo-moar 7a4743b: OUTPUT: «0.54265194␤»
m: my $a = 42; for ^1000000 { my $b = 42 < $a && $a < 666 }; say now - INIT now
<+camelia> rakudo-moar 7a4743b: OUTPUT: «0.2490039␤»

Environment

  • Operating system:

Darwin 16.7.0 Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64 x86_64

  • Compiler version (perl6 -v):

This is Rakudo version 2017.12-111-g8023d21 built on MoarVM version 2017.12-20-g5710340
implementing Perl 6.c.

lizmat added a commit that referenced this issue Jan 5, 2018
- just like with DateTime.new earlier today
- JITting *is* taking place here, so not sure what the difference is
- replacing 1 <= $a <= 12 by 1 <= $a && $a <= 12 would make it 30% faster still
  - but am not sure that's a currently botched optimization in Moar or not
  - so keeping the code like this for now
  - see GH #1368
- also, did not change self === Date to nqp::istype(self.WHAT,Date)
  - because the effect was only about 0.5%, so maybe for later
@zoffixznet zoffixznet self-assigned this Jan 6, 2018
zoffixznet added a commit that referenced this issue Jan 7, 2018
- Makes 2.4x faster chains like 2 < $a < 1337
- Makes 2 < $a < 1337 run about the same speed as 2 < $a && $a < 1337
    Phixes #1368
- With longer chains, the chain version comes out noticeably faster
    than non-chained version with && ops
@zoffixznet
Copy link
Contributor

zoffixznet commented Jan 7, 2018

This is now fixed by b77d875 and accompanying Raku/nqp@4145205

For OP code, the perf is now about the same:

$ ./perl6 -e 'my $a = 42; for ^1000000 { my $b = 42 < $a && $a < 666 }; say now - INIT now'
0.2635152
$ ./perl6 -e 'my $a = 42; for ^1000000 { my $b = 42 < $a < 666 }; say now - INIT now'                                                                                                                           
0.2624662

And with longer chains, the chained version has noticeable perf benefits:

$ ./perl6 -e 'my $a = 42; for ^10_000_000 { my $b = 42 < $a && $a < 666 <= $a && $a <= 666 }; say now - INIT now'
2.6051729
$ ./perl6 -e 'my $a = 42; for ^10_000_000 { my $b = 42 < $a < 666 <= $a <= 666 }; say now - INIT now'
2.5022431

I guess I'm gonna close this without a test, since we don't yet have a solid perf testing framework...

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

2 participants