Home > Back-end > String equals comparison method and the type int the==comparison method, efficiency, fast, low perfo
String equals comparison method and the type int the==comparison method, efficiency, fast, low perfo
Time:09-25
Morning when doing development thought of a problem, the needs of the scene is 100 item in the list (item included in the download task id, download url task variables) such as elements, each item is more real-time refresh, download progress download callback interface progress update method of parameter in three: download task id of type int, String types of links to download the task, there is a download percentage of type int, existing logic is in progress update method according to the type String url search to the item, to refresh the list again, I also tried another way, is to find more ing type task id to the item, to refresh, That I'm confused, the two different data types different comparison method, what kind of the high efficiency of some?
CodePudding user response:
You can test yourself, the comparison of type int is faster than the comparison of type String as a lost
CodePudding user response:
Int definitely faster than equal, equal way to String is after the hash is hash value, is essentially a CPU type operation, if the String is particularly big, calculation process is slow, a String of 1 m should be around 10 ms, but int==method, is the memory between the size of the data comparison, is a simple calculation (add, subtract, multiply or divide,
CodePudding user response:
== Assuming that==operating expenses, time of 10, You go to see inside the equals method again, he had more statements, finally must include at least one==, so spending time equals method more than 10,