-
-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathPerformanceTest.php
More file actions
148 lines (113 loc) · 4.45 KB
/
PerformanceTest.php
File metadata and controls
148 lines (113 loc) · 4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
declare(strict_types=1);
use Relaticle\Flowforge\Services\DecimalPosition;
use Relaticle\Flowforge\Services\PositionRebalancer;
use Relaticle\Flowforge\Tests\Fixtures\Task;
describe('DecimalPosition performance', function () {
test('10,000 position calculations complete in < 100ms', function () {
$start = microtime(true);
for ($i = 0; $i < 10_000; $i++) {
DecimalPosition::between('1000.0000000000', '2000.0000000000');
}
$elapsed = microtime(true) - $start;
expect($elapsed)->toBeLessThan(0.5); // Allow some margin
});
test('10,000 exact midpoint calculations complete in < 50ms', function () {
$start = microtime(true);
for ($i = 0; $i < 10_000; $i++) {
DecimalPosition::betweenExact('1000.0000000000', '2000.0000000000');
}
$elapsed = microtime(true) - $start;
expect($elapsed)->toBeLessThan(0.25); // CI runners have variable performance
});
test('10,000 normalize operations complete in < 50ms', function () {
$values = ['1000', '1000.5', 1000, 1000.5, '-500'];
$start = microtime(true);
for ($i = 0; $i < 10_000; $i++) {
DecimalPosition::normalize($values[$i % 5]);
}
$elapsed = microtime(true) - $start;
expect($elapsed)->toBeLessThan(0.25); // CI runners have variable performance
});
});
describe('PositionRebalancer performance', function () {
test('rebalancing 100 cards completes in < 2 seconds', function () {
// Create 100 cards with positions
for ($i = 0; $i < 100; $i++) {
Task::create([
'title' => "Card {$i}",
'status' => 'todo',
'order_position' => DecimalPosition::normalize($i * 100),
]);
}
$rebalancer = new PositionRebalancer;
$start = microtime(true);
$count = $rebalancer->rebalanceColumn(
Task::query(),
'status',
'todo',
'order_position'
);
$elapsed = microtime(true) - $start;
expect($count)->toBe(100)
->and($elapsed)->toBeLessThan(2.0);
});
test('gap statistics on 100 cards completes in < 500ms', function () {
// Create 100 cards with positions
for ($i = 0; $i < 100; $i++) {
Task::create([
'title' => "Card {$i}",
'status' => 'todo',
'order_position' => DecimalPosition::normalize($i * 100),
]);
}
$rebalancer = new PositionRebalancer;
$start = microtime(true);
$stats = $rebalancer->getGapStatistics(
Task::query(),
'status',
'todo',
'order_position'
);
$elapsed = microtime(true) - $start;
expect($stats['count'])->toBe(100)
->and($elapsed)->toBeLessThan(0.5);
});
});
describe('sequence generation performance', function () {
test('generating 1000 sequential positions completes in < 50ms', function () {
$start = microtime(true);
$positions = DecimalPosition::generateSequence(1000);
$elapsed = microtime(true) - $start;
expect($positions)->toHaveCount(1000)
->and($elapsed)->toBeLessThan(0.5); // CI runners have variable performance
});
test('generating 100 between positions completes in < 50ms', function () {
$start = microtime(true);
$positions = DecimalPosition::generateBetween('1000', '2000', 100);
$elapsed = microtime(true) - $start;
expect($positions)->toHaveCount(100)
->and($elapsed)->toBeLessThan(0.25); // CI runners have variable performance
});
});
describe('comparison performance', function () {
test('10,000 comparisons complete in < 50ms', function () {
$positions = [];
for ($i = 0; $i < 100; $i++) {
$positions[] = DecimalPosition::normalize($i * 1000);
}
$start = microtime(true);
$count = 0;
for ($i = 0; $i < 10_000; $i++) {
$a = $positions[$i % 100];
$b = $positions[($i + 1) % 100];
DecimalPosition::compare($a, $b);
DecimalPosition::lessThan($a, $b);
DecimalPosition::greaterThan($a, $b);
$count++;
}
$elapsed = microtime(true) - $start;
expect($count)->toBe(10_000)
->and($elapsed)->toBeLessThan(0.25); // CI runners have variable performance
});
});