bash - How do I speed this up? -


Creates a list of the following code names and 'numbers' and gives random intervals between each and every person between 15 and 90.

  #! / Bin / sh file = $ 1 n = $ 2 # If the number exits zero then exit [0f] then echo "$ n people's generating list." For 'seq 1 $ n` in; "NUM = ($ RANDOM% 75) +15" resonance "name $ i $ NUM (###) ### - ####" gt; & Gt; $ File expired "list generated."  

With this, I am trying to create a list of 1M names. It is slow, I expected that; It was so slow that I lost patience and tried 10 names. It was also slow, but it was done in a few seconds.

Because of this I am generating the name, it is sort of sorting. I am surprised that when I solved the list of 10K names, it was immediately.

How can this be?

Is there anything that is slowing down by being undeclared? Both are sorting and generating files, so how fast the sorting can be done? Is my random number math in the list generator slowing down?

This is my sorting script.

  #! / Bin / sh # is the first logic to be sorted, second output file tr -s '' & lt; $ 1 | Sort-n -k2 & gt; $ 2  

No new answer, just new code.

It is that IMHO is a good medium path between good and efficient codes (as you can be skilled in Bash, this is slow, it is a shell ...)

For
  ((i = 1; i & lt; = n; i ++)); Do "name $ i $ ((NUM = (random% 75) + 15)) (###) ### - ####" done » "$ File"  

Optional, do not use classic counter loop

  i = 1 while ((i & lt; = n)); Do "$ $ ((i ++)) $ ((NUM = (Random% 75) +15)) (###) ### - ####" done & gt; "$ File"  

Both are about the same speed.

The fixes outlined by all other people are the same:

  • Use shell arithmetic
  • Ah, and use of quote Do it, but it is for discretion, not for speed

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -