Новости | FAQ | Авторы | Документация | В действии | Библиотека |
Инструменты | Полезные ссылки | Хостинги | Скачать | Примеры | Форум |
nkostya 07.12.2022 12:06
Проверяем выделение памяти под строку############################################################################## @handle[data] ^memory:compact[] $console:line[1: ^inspect[$Rusage:total]] $data[^for[](0;10000){a}] ^memory:compact[] $console:line[3: ^inspect[$Rusage:total]] $result[] #end @handle[]Получаем изменение used 128 КБ.
1: {"time" => "0.071723", "utime" => "0.048915", "stime" => "0.012147", "memory_block" => "10032", "memory" => "8116", "memory_used" => "8116", "memory_free" => "2560", "memory_allocated_since_start" => "12075.265625"}Добавляем освобождение переменной
3: {"time" => "0.074693", "utime" => "0.051879", "stime" => "0.012147", "memory_block" => "10032", "memory" => "8244", "memory_used" => "8244", "memory_free" => "2432", "memory_allocated_since_start" => "12367.578125"}
############################################################################## @handle[data] ^memory:compact[] $console:line[1: ^inspect[$Rusage:total]] $data[^for[](0;10000){a}] $data[] ^memory:compact[] $console:line[3: ^inspect[$Rusage:total]] $result[] #end @handle[]Результаты
1: {"time" => "0.081939", "utime" => "0.045759", "stime" => "0.018075", "memory_block" => "10624", "memory" => "8120", "memory_used" => "8120", "memory_free" => "2556", "memory_allocated_since_start" => "12078.921875"}used даже выросло
3: {"time" => "0.08601", "utime" => "0.049733", "stime" => "0.018158", "memory_block" => "10624", "memory" => "8248", "memory_used" => "8248", "memory_free" => "2428", "memory_allocated_since_start" => "12366.71875"}
############################################################################## @handle[data] ^memory:compact[] $data[^for[](0;10000){a}] $console:line[1: ^inspect[$Rusage:total]] ^work[] $console:line[2: ^inspect[$Rusage:total]] ^memory:compact[] $console:line[3: ^inspect[$Rusage:total]] $result[] #end @handle[] ############################################################################## @work[data][locals] $cache[^hash::create[]] ^for[i](0;100000){ $cache.[$i][$data] } #end @work[]Получаем:
1: {"time" => "0.081677", "utime" => "0.029812", "stime" => "0.033566", "memory_block" => "9856", "memory" => "8240", "memory_used" => "8240", "memory_free" => "2436", "memory_allocated_since_start" => "12333.546875"}Видим что память частично освободилась, но явно не на столько, что мы сгенерировали в @work
2: {"time" => "0.240556", "utime" => "0.188699", "stime" => "0.033576", "memory_block" => "25432", "memory" => "23960", "memory_used" => "23960", "memory_free" => "2220", "memory_allocated_since_start" => "31989.96875"}
3: {"time" => "0.247554", "utime" => "0.195687", "stime" => "0.033576", "memory_block" => "25432", "memory" => "20248", "memory_used" => "20248", "memory_free" => "5932", "memory_allocated_since_start" => "32027.40625"}
############################################################################## @handle[data] ^memory:compact[] $data[^for[](0;10000){a}] $console:line[1: ^stat[$status:memory]] ^work[] $console:line[2: ^stat[$status:memory]] ^memory:compact[] $console:line[3: ^stat[$status:memory]] $result[] #end @handle[] ############################################################################## @stat[stat] $result[used: $stat.used, free: $stat.free, ever_allocated_since_compact: $stat.ever_allocated_since_compact, ever_allocated_since_start: $stat.ever_allocated_since_start] #end @stat[] ############################################################################## @work[data][locals] $cache[^hash::create[]] ^for[i](0;100000){ $cache.[$i][$data] } #end @work[]Получаем
1: used: 8760, free: 2544, ever_allocated_since_compact: 252.203125, ever_allocated_since_start: 12891.203125Получаем что на выполнение work было выделено 15 708 (15МБ ?)
2: used: 24468, free: 2340, ever_allocated_since_compact: 19876.75, ever_allocated_since_start: 32515.75
3: used: 20728, free: 6080, ever_allocated_since_compact: 0, ever_allocated_since_start: 32515.75