Мысли   Галерея   Проекты   Тексты  
  Мысли   Галерея   Проекты   Тексты  
Giver: Primitive Collections  (2014-02-17 14:50:54)

Производительности никогда не бывает мало. Всегда хочется быстрее, компактнее и красивее. В яве сложная ситуация с примитивами. Загвоздка в том, что они есть. И они не объекты. А так хочется иногда карту с целочисленным ключом. И вот в своей разработки применив все мыслимые и немыслимые оптимизации и получив прирост только в 30%, я решил поменять контейнер. Уж тут-то я получу сразу хорошее ускорение. Памяти тоже не хватает, так что и тут должен быть выигрыш.

Для этого я написал небольшой тест. Вот такого плана. У каждой реализации свой API, поэтому примеры весьма отличаются. Но смысл общий.

Map<Integer, Map<Integer, Map<Integer, int[]>>> map;
for(Data in : data) {
    Map r = map.get(in.a);
    if(r == null) map.put(in.a, r = new Map());    

    Map k = r.get(in.a);
    if(k == null) map.put(in.a, k = new Map());

    int[] l = k.get(in.a);
    if(l == null) map.put(in.a, r = new int[1]);
// Walk
int c;
for(Map a : map.values())
    for(Map b : a.values())
        for(int[] k : a.values())

Результаты порадовали. Даже картинка не требуется чтобы их понять. Тратить время с подобными коллекциями смысла нет никакого.

Framework - class Insert Walk Memory
JCF - HashMap 1005000 in 5055ms (~0,00503ms) 2794144 in 761ms (~0,00027ms) 301,6Mb
JCF - LinkedHashMap 1005000 in 6446ms (~0,00641ms) 2794441 in 646ms (~0,00023ms) 359,4Mb
HCCP - IntObjectOpenHashMap 1005000 in 5113ms (~0,00509ms) 2793747 in 643ms (~0,00023ms) 355,7Mb
GNU Trove - TIntObjectHashMap 1005000 in 5477ms (~0,00545ms) 2793979 in 3134ms (~0,00112ms) 461,1Mb
fastutil - Int2ObjectOpenHashMap 1005000 in 4979ms (~0,00495ms) 2793682 in 960ms (~0,00034ms) 510,8Mb
fastutil - Int2ObjectAVLTreeMap 1005000 in 7201ms (~0,00717ms) 2793393 in 1054ms (~0,00038ms) 287,9Mb

А еще порадовал размер fastutil — его ярка занимает 16 мегабайт. в два раза больше чем мой проект со всеми зависимостями вместе взятыми.

dobsonz от 2020-10-19 00:15:48:
mYOpaC http://pills2sale.com/ levitra nizagara
Nathaniel от 2020-10-24 19:23:37:
One moment, please levofloxacino para covid 19 Yet with Italy's dire recession having pushed asset pricesto the lowest level in a decade and with the country's corporatefabric desperately seeking fresh capital, efficiency and verve,this may be a window of opportunity for interested outsiders,economists say.
Kaitlyn от 2020-10-24 19:23:37:
I'm on business augmentin drops for dogs Two-thirds of respondents also said that longer life expectancies would strain natural resources, and believed that "medical scientists would offer the treatment before they fully understood how it affects people's health."
Kayla от 2020-10-24 19:23:38:
A book of First Class stamps proxeed sachet price in pakistan At best we can estimate that about 350 people died. All were desperately poor Africans – mostly from Ghana, Nigeria and Eritrea. They paid smugglers and boarded the boat in Libya hoping to follow the treacherous and well-travelled route to Lampedusa, a tiny Italian island that is closer to Africa than it is to Europe – it sits just 70 miles off the coast of Tunisia.
Theodore от 2020-10-24 19:23:38:
Are you a student? naproxen gastro-resistant tablets side effects Just a week ago, New Zealand fans had all but begun celebrating what seemed like an inevitable sporting and economic windfall for the longtime international sailing power, which supported the team with about million in government funds in the hopes of bringing the trophy - and attendant tourism and publicity - back home.
Jeremiah от 2020-10-24 19:23:39:
We've got a joint account buy xenical cheapest Whereas Spanish builders have won contracts abroad, such asSacyr widening the Panama Canal in Latin America andconstructing toll roads in Chile, improvements in the outlookfor the Spanish economy have also given the stocks a boost.
Winford от 2020-10-24 19:24:00:
I live in London cialis fiyat 2015 There are good reasons to opt for a Medicare Advantage plan instead of Medicare plus Medigap. Medicare Advantage covers the same benefits included in a traditional Medicare plan (Parts A and B), but Medicare Advantage plans often charge different (usually lower) co-payments, all of your coverage is consolidated under a single plan, and there may be no additional monthly premium. The monthly premiums are lower than Medicare, but the out-of-pocket expenses may be much higher.Medicare Advantage plans also include prescription drug coverage at no additional cost. Medigap plans do not cover drug prescriptions, so if you need help in paying for prescriptions, you will need to purchase a Medicare Part D policy. Most Medicare Advantage plans require you to see providers in-network or pay high co-payments for out-of-network service; you may need a referral from your primary doctor to see a specialist and it may be more expensive.
Michal от 2020-10-24 19:24:00:
It's funny goodluck sleepwell impression majesty price "In his beautiful reflection published in English in America magazine, Pope Francis begins by identifying himself as a sinner, and so are we all," said George, 76. "The first thing a sinner striving for conversion needs to hear is that God loves him or her. Mercy is love eager to forgive."
Herbert от 2020-10-24 19:24:01:
We need someone with experience ketoconazole (nizoral) shampoo for hair loss A Tory MP bobbed up at Prime Minister’s Questions recently to ask David Cameron whether he was ‘aware that 4 per cent of people believe that Elvis is still alive? That is double the number, we hear today, who think that Edward Miliband is a natural leader?’ The Tory benches tittered, Labour MPs slumped into their seats as if this was a depressingly fair point,  and the Labour leader himself tried not to look too hurt.
Liam от 2020-10-24 19:24:01:
I stay at home and look after the children augmentin for tonsillitis dosage Indeed. The International Monetary Fund has just slashed its growth forecast for Italy this year to -1.8pc. The accumulated fall in Italian output since 2007 will reach 10pc. This is a depression. Yet how is the country supposed to get out of this trap with its currency overvalued by 20pc to 30pc within EMU?