Skip to content

Instantly share code, notes, and snippets.

@jnthn jnthn/o.p6 Secret
Created Sep 25, 2018

Embed
What would you like to do?
class Point {
has $.x;
has $.y;
}
my $total = 0;
for ^1_000_000 {
my $p = Point.new(x => 2, y => 3);
$total = $total + $p.x + $p.y;
}
say $total;
use v5.10;
package Point;
sub new {
my ($class, %args) = @_;
bless \%args, $class;
}
sub x {
my $self = shift;
$self->{x}
}
sub y {
my $self = shift;
$self->{y}
}
package MAIN;
my $total = 0;
for (1..1_000_000) {
my $p = Point->new(x => 2, y => 3);
$total = $total + $p->x + $p->y;
}
say $total;
@b2gills

This comment has been minimized.

Copy link

commented Sep 26, 2018

If I was writing this in Perl5 I might have done something like

sub x {
    my ($self) = @_;
    $self->{x}
}

Which is faster on newer versions of perl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.