#!/usr/bin/perl
use strict;
use warnings;

use lib qw(modules);
use Memory::Usage;
use SimpleObjectRegistry;
use SimpleObject;

my $mu;
$mu = Memory::Usage->new();


my @array = map { SimpleObject->create( id => int(rand(1000000)), id2=>$_ )   }  (1..1_000_000);

$mu->record('after array construction');

my $reg = SimpleObjectRegistry->create();
$reg->add_objects_from_ref(\@array);
$mu->record('after registry population');

$reg->sort_objects(\&sort_func);
$mu->record('after sorting');


my $count = 0;
foreach ($reg->object_list() )  {
    print $_->{id} , "\n";
    last if $count++ > 10;
}
$mu->record('at end');
$mu->dump() ;

sub sort_func {
    my($a, $b) = @_;
    $b->{id} <=> $a->{id}
    || $b->get_attribute("id2") <=> $a->get_attribute("id2");

};



