<div dir="ltr">I have s simple code to create and update maps.<div>and using timer:tc to measure the time costed by this operations.</div><div><br></div><div><br></div><div>file aa.erl</div><div><br></div><div><br></div><div><div>-module(aa).</div><div><br></div><div>-export([create/1,</div><div> update/1]).</div><div><br></div><div>-record(person, {id, x, y, angle, speed}).</div><div><br></div><div>create(Num) -></div><div> create(Num, #{}).</div><div><br></div><div>update(M) -></div><div> Size = maps:size(M),</div><div> Fun = fun(K, V) -></div><div> X = Size - K,</div><div> V#person{x=X,y=X,angle=X,speed=X}</div><div> end,</div><div><br></div><div> maps:map(Fun, M).</div><div><br></div><div><br></div><div>create(0, M) -></div><div> M;</div><div><br></div><div>create(N, M) -></div><div> M1 = M#{N => #person{id=N, x=N, y=N, angle=N, speed=N}},</div><div> create(N-1, M1).</div></div><div><br></div><div><br></div><div>-----------------------------</div><div>file aa.escript</div><div><br></div><div><div>#!/usr/bin/env escript</div><div><br></div><div><br></div><div>main(_) -></div><div> io:format("Start~n"),</div><div><br></div><div><br></div><div> {T, M} = timer:tc(aa, create, [10000]),</div><div> io:format("create cost ms: ~p~n", [T / 1000]),</div><div><br></div><div> {T1, M1} = timer:tc(aa, update, [M]),</div><div> io:format("update cost ms: ~p~n", [T1 / 1000]),</div><div> ok.</div><div><br></div><div>---------------------------------------</div></div><div><br></div><div>When run with escript, the outputs are:</div><div><br></div><div><br></div><div><div>wang[02:31][~/Learn]$ ./aa.escript </div><div>./aa.escript:11: Warning: variable 'M1' is unused</div><div>Start</div><div>create cost ms: 7.344</div><div>update cost ms: 5.903</div><div>wang[02:31][~/Learn]$ ./aa.escript </div><div>./aa.escript:11: Warning: variable 'M1' is unused</div><div>Start</div><div>create cost ms: 7.077</div><div>update cost ms: 5.484</div><div>wang[02:31][~/Learn]$ ./aa.escript </div><div>./aa.escript:11: Warning: variable 'M1' is unused</div><div>Start</div><div>create cost ms: 7.006</div><div>update cost ms: 5.438</div><div>wang[02:31][~/Learn]$ </div></div><div><br></div><div><br></div><div>--------------------------------------------</div><div><br></div><div>But when I run in erl shell, the outputs are:</div><div><br></div><div><div>wang[02:32][~/Learn]$ erl</div><div>Erlang/OTP 19 [erts-8.0] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]</div><div><br></div><div>Eshell V8.0 (abort with ^G)</div><div>1> {T, M} = timer:tc(aa, create, [10000]).</div><div>{19523,</div><div> #{462 => {person,462,462,462,462,462},</div><div> 704 => {person,704,704,704,704,704},</div><div> 7994 => {person,7994,7994,7994,7994,7994},</div><div> 6850 => {person,6850,6850,6850,6850,6850},</div><div> 6836 => {person,6836,6836,6836,6836,6836},</div><div> 9765 => {person,9765,9765,9765,9765,9765},</div><div> 6653 => {person,6653,6653,6653,6653,6653},</div><div> 5961 => {person,5961,5961,5961,5961,5961},</div><div> 1328 => {person,1328,1328,1328,1328,1328},</div><div> 4351 => {person,4351,4351,4351,4351,4351},</div><div> 8373 => {person,8373,8373,8373,8373,8373},</div><div> 6749 => {person,6749,6749,6749,6749,6749},</div><div> 9406 => {person,9406,9406,9406,9406,9406},</div><div> 8441 => {person,8441,8441,8441,8441,8441},</div><div> 6570 => {person,6570,6570,6570,6570,6570},</div><div> 6074 => {person,6074,6074,6074,6074,6074},</div><div> 3590 => {person,3590,3590,3590,3590,3590},</div><div> 7636 => {person,7636,7636,7636,7636,7636},</div><div> 5934 => {person,5934,5934,5934,5934,5934},</div><div> 4631 => {person,4631,4631,4631,4631,4631},</div><div> 1935 => {person,1935,1935,1935,1935,1935},</div><div> 8406 => {person,8406,8406,8406,8406,...},</div><div> 9860 => {person,9860,9860,9860,...},</div><div> 3742 => {person,3742,3742,...},</div><div> 9221 => {person,9221,...},</div><div> 4969 => {person,...},</div><div> 9846 => {...},...}}</div><div>2> T / 1000.</div><div>19.523</div><div>3> </div><div>3> {T1, M1} = timer:tc(aa, update, [M]).</div><div>{16920,</div><div> #{462 => {person,462,9538,9538,9538,9538},</div><div> 704 => {person,704,9296,9296,9296,9296},</div><div> 7994 => {person,7994,2006,2006,2006,2006},</div><div> 6850 => {person,6850,3150,3150,3150,3150},</div><div> 6836 => {person,6836,3164,3164,3164,3164},</div><div> 9765 => {person,9765,235,235,235,235},</div><div> 6653 => {person,6653,3347,3347,3347,3347},</div><div> 5961 => {person,5961,4039,4039,4039,4039},</div><div> 1328 => {person,1328,8672,8672,8672,8672},</div><div> 4351 => {person,4351,5649,5649,5649,5649},</div><div> 8373 => {person,8373,1627,1627,1627,1627},</div><div> 6749 => {person,6749,3251,3251,3251,3251},</div><div> 9406 => {person,9406,594,594,594,594},</div><div> 8441 => {person,8441,1559,1559,1559,1559},</div><div> 6570 => {person,6570,3430,3430,3430,3430},</div><div> 6074 => {person,6074,3926,3926,3926,3926},</div><div> 3590 => {person,3590,6410,6410,6410,6410},</div><div> 7636 => {person,7636,2364,2364,2364,2364},</div><div> 5934 => {person,5934,4066,4066,4066,4066},</div><div> 4631 => {person,4631,5369,5369,5369,5369},</div><div> 1935 => {person,1935,8065,8065,8065,8065},</div><div> 8406 => {person,8406,1594,1594,1594,...},</div><div> 9860 => {person,9860,140,140,...},</div><div> 3742 => {person,3742,6258,...},</div><div> 9221 => {person,9221,...},</div><div> 4969 => {person,...},</div><div> 9846 => {...},...}}</div><div>4> </div><div>4> T1 / 1000.</div><div>16.92</div><div>5> </div></div><div><br></div><div><br></div><div>the create time is 19ms, and update time is 17ms</div><div>the escript running time is 7ms and 5 ms.</div><div><br></div><div>Why in the erl shell, there is slower than escript? </div><div><br></div><div><br></div><div><br></div><div>So, when I run my erlang application via: erl -pa xxx -s myapp start -detached .</div><div>Is it as slow as running with erl shell ?</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br clear="all"><div><br></div><div><br></div><div><br></div><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr">My GitHub<br><a href="https://github.com/yueyoum" target="_blank">https://github.com/yueyoum</a><br><br></div></div>
</div></div>