<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal>maps:put/3 in R17rc1 on Windows (64 bit) runs slowly when a<o:p></o:p></p><p class=MsoNormal>large number of randomly generated keys are inserted into a<o:p></o:p></p><p class=MsoNormal>map. The following table shows that the time to insert n<o:p></o:p></p><p class=MsoNormal>keys grows quadratically, so the time to insert a single key<o:p></o:p></p><p class=MsoNormal>grows linearly. Note that performance is greatly improved<o:p></o:p></p><p class=MsoNormal>by using a dict (from stdlib).<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Number Insert into map Insert into dict<o:p></o:p></p><p class=MsoNormal>of keys (milliseconds) (milliseconds) <o:p></o:p></p><p class=MsoNormal>10000 969 16<o:p></o:p></p><p class=MsoNormal>20000 4031 62<o:p></o:p></p><p class=MsoNormal>40000 15937 172<o:p></o:p></p><p class=MsoNormal>80000 63734 453<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>The following code was used for these tests. The dict<o:p></o:p></p><p class=MsoNormal>tests used the same code with dict:new/0 and dict:store/3<o:p></o:p></p><p class=MsoNormal>replacing maps:new/0 and maps:put/3, respectively.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>-module(testmap).<o:p></o:p></p><p class=MsoNormal>-export([start/1]).<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>loop(Map, 0) -> Map;<o:p></o:p></p><p class=MsoNormal>loop(Map, Times) -><o:p></o:p></p><p class=MsoNormal> Key = random:uniform(999999),<o:p></o:p></p><p class=MsoNormal> loop(maps:put(Key, true, Map), Times - 1).<o:p></o:p></p><p class=MsoNormal> <o:p></o:p></p><p class=MsoNormal>start(NumKeys) -><o:p></o:p></p><p class=MsoNormal> {A, B, C} = now(),<o:p></o:p></p><p class=MsoNormal> random:seed(A, B, C),<o:p></o:p></p><p class=MsoNormal> Before = (1000000 * A + B) * 1000 + C div 1000,<o:p></o:p></p><p class=MsoNormal> loop(maps:new(), NumKeys),<o:p></o:p></p><p class=MsoNormal> {E, F, G} = now(),<o:p></o:p></p><p class=MsoNormal> After = (1000000 * E + F) * 1000 + G div 1000,<o:p></o:p></p><p class=MsoNormal> io:format("Elapsed time: ~w milliseconds.~n",<o:p></o:p></p><p class=MsoNormal> [After - Before]).<o:p></o:p></p></div></body></html>