-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
use strict; | ||
use warnings; | ||
|
||
use Test::More; | ||
use Time::HiRes 'time'; | ||
use Clone 'clone'; | ||
|
||
# Skip unless the user explicitly asked for it. | ||
plan skip_all => 'Costs some time and is not very valid. Set TEST_SLACK to a true value to run.' | ||
unless $ENV{TEST_SLACK}; | ||
|
||
use_ok 'EventStore::Tiny'; | ||
|
||
# Preparation method for event stores that have some work to do | ||
sub work { | ||
my $es = shift; | ||
|
||
# Set up | ||
my $data_cells = 10; | ||
my $data_points = 1_000; | ||
my $data_access = 1_000; | ||
|
||
# Event type | ||
$es->register_event(Answered => sub { | ||
my $state = shift; # No data neccessary here | ||
$state->{deep}[int rand $data_cells]{data}{rand()} = 42; | ||
}); | ||
|
||
# Inject some data | ||
$es->store_event('Answered') for 1 .. $data_points; | ||
|
||
# Trigger event application | ||
# With caching on, this is slow because it calls 'clone' for each access | ||
$es->snapshot for 1 .. $data_access; | ||
} | ||
|
||
my $strict_runtime; | ||
subtest 'Strict' => sub { | ||
|
||
# Prepare event store | ||
my $strict = EventStore::Tiny->new( | ||
logger => undef, | ||
cache_distance => 0, # Use caching. This is the default, but anyway | ||
); | ||
|
||
# Work | ||
my $start = time; | ||
work($strict); | ||
$strict_runtime = time - $start; | ||
|
||
# Time spent | ||
ok $strict_runtime > 0, 'Time spent'; | ||
note "Strict runtime: $strict_runtime"; | ||
|
||
subtest 'Strict data handling' => sub { | ||
$strict->snapshot->state->{deep}[3] = 17; | ||
isnt $strict->snapshot->state->{deep}[3] => 17, 'State preserved'; | ||
}; | ||
}; | ||
|
||
subtest 'Slack' => sub { | ||
|
||
# Prepare non-strict event store | ||
my $slack = EventStore::Tiny->new( | ||
logger => undef, | ||
cache_distance => 0, # Use caching. This is the default, but anyway | ||
slack => 1, | ||
); | ||
|
||
# Work | ||
my $start = time; | ||
work($slack); | ||
my $slack_runtime = time - $start; | ||
|
||
# Time spent | ||
ok $slack_runtime > 0, 'Time spent'; | ||
note "Slack runtime: $slack_runtime"; | ||
|
||
subtest 'Non-strict data handling' => sub { | ||
$slack->snapshot->state->{deep}[3] = 17; | ||
is $slack->snapshot->state->{deep}[3] => 17, 'State modified'; | ||
}; | ||
|
||
# Compare | ||
ok $slack_runtime < $strict_runtime * 0.2, 'Improved runtime'; | ||
}; | ||
|
||
done_testing; | ||
|
||
__END__ |