How expensive is Java string encoding conversion?

I was wondering how expensive Java string encoding conversion algorithms are, say, text fragments in EBCDIC that need to be converted to UTF-16 or for a similar conversion of a large file. Are there any guidelines for the value of this conversion? Tests for multiple encodings will be better.

+3
source share
3 answers

This is the O (n) algorithm. The time taken to execute will increase more or less linearly with the length of the string you are converting (although if you are converting millions of very short lines, the additional overhead of function calls will be added to this).

In almost all situations this will not be a bottleneck. You could probably encode very large strings of several tens of megabytes in a short amount of time. However, I have no actual control data.

+3
source

I suspect this is negligible. I'm more worried about the cost of allocating new String objects if you convert thousands of strings or allocate huge byte arrays if you convert very large strings. But even then, only in extreme circumstances.

+1
source

- Java .

This does not mean that it would be impossible to create an even more efficient specialized algorithm or, possibly, an interface to an optimized library of native codes for a few percent of additional performance. But if you do not have many servers where coding takes up a significant part of the processor time, it is unlikely to be worth the effort.

0
source

Source: https://habr.com/ru/post/1706863/


All Articles