- 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.
- Implementing Modern DevOps
- C程序設計簡明教程(第二版)
- Developing Mobile Web ArcGIS Applications
- PHP程序設計(慕課版)
- Java:Data Science Made Easy
- Ext JS 4 Web Application Development Cookbook
- C#程序設計
- Responsive Web Design by Example
- Internet of Things with ESP8266
- HTML5開發精要與實例詳解
- Spring Boot實戰
- CRYENGINE Game Development Blueprints
- Scala Functional Programming Patterns
- Exploring SE for Android
- Android高級開發實戰:UI、NDK與安全