[ 
https://issues.apache.org/jira/browse/OPENNLP-363?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13146577#comment-13146577
 ] 

Aliaksandr Autayeu commented on OPENNLP-363:
--------------------------------------------

OK, although for me the first one reads better via addAll and subList.

My understanding is that system copy is generally faster, as seems to be the 
opinion of many others. Some find bigger differences, some find smaller ones. 
Some quotes:
====================
http://stackoverflow.com/questions/1920981/when-and-why-should-i-use-system-arraycopy-or-arrays-vs-collections
The alternative to System.arraycopy(...) with arrays is writing a loop and 
copying elements manually. This is
* More code
* Thus, more likely to contain an error
* In most cases slower because System.arraycopy(...) is a native method that 
can use fast memory copy routines provided by the OS.
====================
"System.arraycopy(...) is a native method that can use fast memory copy 
routines provided by the OS."
====================

One can also take a test class from here: 
http://www.velocityreviews.com/forums/t134419-system-arraycopy-speed.html and 
make few runs. Here is a quote:

Array size: 1000, Repetitions: 5
Loop: 0ms, System.arrayCopy:0ms

Array size: 1000, Repetitions: 500
Loop: 15ms, System.arrayCopy:0ms

Array size: 100000, Repetitions: 50
Loop: 31ms, System.arrayCopy:15ms

Array size: 100000, Repetitions: 500
Loop: 360ms, System.arrayCopy:31ms

Array size: 100000, Repetitions: 5000
Loop: 3640ms, System.arrayCopy:250ms

For smaller arrays I did it myself right now:

Array size: 5, Repetitions: 1000
Loop: 1ms, System.arrayCopy:0ms

Array size: 500, Repetitions: 1000
Loop: 126ms, System.arrayCopy:1ms

Array size: 5, Repetitions: 100000
Loop: 4ms, System.arrayCopy:27ms

Array size: 50, Repetitions: 100000
Loop: 8ms, System.arrayCopy:25ms

Array size: 500, Repetitions: 100000
Loop: 69ms, System.arrayCopy:36ms

Array size: 5000, Repetitions: 100000
Loop: 492ms, System.arrayCopy:331ms

So, there is no doubt on large arrays. On small arrays it is less clear.
                
> performance-issues: manual array or collection copy,  appending strings, 
> string creation, extra .toString()
> -----------------------------------------------------------------------------------------------------------
>
>                 Key: OPENNLP-363
>                 URL: https://issues.apache.org/jira/browse/OPENNLP-363
>             Project: OpenNLP
>          Issue Type: Improvement
>    Affects Versions: tools-1.5.3-incubating, maxent-3.0.3-incubating
>            Reporter: Aliaksandr Autayeu
>            Priority: Minor
>              Labels: patch
>         Attachments: 
> 0003-performance-issues-manual-array-or-collection-copy-a.patch
>
>   Original Estimate: 2h
>  Remaining Estimate: 2h
>
> There are multiple performance nuisances: manual array or collection copy, 
> appending strings, string creation, extra .toString() calls.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to