- Learning Concurrency in Kotlin
- Miguel Angel Castiblanco Torres
- 200字
- 2021-08-05 10:46:41
CPU-bound
Many algorithms are built around operations that need only the CPU to be completed. The performance of such algorithms will be delimited by the CPU in which they are running, and solely upgrading the CPU will usually improve their performance.
Let's think, for example, of a simple algorithm that takes a word and returns whether it's a palindrome or not:
fun isPalindrome(word: String) : Boolean {
val lcWord = word.toLowerCase()
return lcWord == lcWord.reversed()
}
Now, let's consider that this function is called from another function, filterPalindromes(), which takes a list of words and returns the ones that are palindromes:
fun filterPalindromes(words: List<String>) : List<String> {
return words.filter { isPalindrome(it) }
}
Finally, filterPalindromes() is called from the main method of the application where a list of words has been already defined:
val words = listOf("level", "pope", "needle", "Anna", "Pete", "noon", "stats")
fun main(args: Array<String>) {
filterPalindromes(words).forEach {
println(it)
}
}
In this example, all the parts of the execution depend on the CPU. If the code is updated to send hundreds of thousands of words, filterPalindromes() will take longer. Also, if the code is executed in a faster CPU, the performance will be improved without code changes.
- Software Defined Networking with OpenFlow
- ASP.NET Core 5.0開發入門與實戰
- ASP.NET Core Essentials
- 利用Python進行數據分析(原書第3版)
- Python忍者秘籍
- Mastering JavaScript Design Patterns(Second Edition)
- 青少年信息學競賽
- 動手學數據結構與算法
- Unity 2018 Augmented Reality Projects
- GitHub入門與實踐
- Instant jQuery Boilerplate for Plugins
- SwiftUI極簡開發
- 深入淺出Python數據分析
- 計算機應用基礎(第二版)
- ROS機器人編程實戰