我正在实现一个用于测量问题复杂性的测试框架,方法是查看随着问题大小(1000、10000、100000等)的增加而消耗的时间如何变化。
我想用更大的数字进行测试,因为以较小的数字运行这些测试所花费的时间可能相差很大。但是,当堆内存不足时,node
进程将崩溃。当我尝试分配大小为100000000的数组时,就会发生这种情况。
以下是错误输出:
<--- Last few GCs --->
[16528:000001D288DD3880] 58236 ms: Scavenge 467.8 (490.7) -> 452.1 (490.7) MB, 0.5 / 0.0 ms (average mu = 0.954, current mu = 0.951) allocation failure
[16528:000001D288DD3880] 58263 ms: Scavenge 467.8 (490.7) -> 452.1 (490.7) MB, 0.5 / 0.0 ms (average mu = 0.954, current mu = 0.951) allocation failure
[16528:000001D288DD3880] 58283 ms: Scavenge 467.8 (490.7) -> 452.1 (490.7) MB, 0.4 / 0.0 ms (average mu = 0.954, current mu = 0.951) allocation failure
<--- JS stacktrace --->
==== JS stack trace =========================================
0: ExitFrame [pc: 0000033BDAD5C5C1]
Security context: 0x00b07821e6e9 <JSObject>
1: getArray [00000171693C1EA1] [file.ts~7] [pc=0000033BDAFFEC3F](this=0x01716938e449 <Object map = 000000223D38E439>,length=100000000,max=0x025631721d11 <Number 9.0072e+15>)
2: heapsortTest(aka heapsortTest) [0000002040FFF699] [...
FATAL ERROR: invalid array length Allocation failed - JavaScript heap out of memory
1: 00007FF73EC6F04A v8::internal::GCIdleTimeHandler::GCIdleTimeHandler+5114
2: 00007FF73EC4A0C6 node::MakeCallback+4518
3: 00007FF73EC4AA30 node_module_register+2032
4: 00007FF73EED20EE v8::internal::FatalProcessOutOfMemory+846
5: 00007FF73EED201F v8::internal::FatalProcessOutOfMemory+639
6: 00007FF73F3F2BC4 v8::internal::Heap::MaxHeapGrowingFactor+9556
7: 00007FF73EFADC70 v8::internal::Factory::NewFixedDoubleArray+240
8: 00007FF73F025F8B v8::internal::HashTable<v8::internal::NumberDictionary,v8::internal::NumberDictionaryShape>::KeyAt+60555
9: 00007FF73F013916 v8::internal::HashTable<v8::internal::NumberDictionary,v8::internal::NumberDictionaryShape>::EntryToIndex+66198
10: 00007FF73F416B60 v8::internal::Bitmap::IsClean+29728
11: 0000033BDAD5C5C1
这是我运行流程的方式:
node -r ts-node/register --max-old-space-size=8192 --expose-gc heap/heapsort-test.ts
我的机器有16 GB RAM。
我该怎么做才能进行更大的测试?