Skip to content

robertmryan/CountWhitePixels

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Count White Pixels

See https://stackoverflow.com/a/58513549/1271826

This is quick-and-dirty example of using concurrentPerform to parallelize a for loop.

This will let the user select an image from their photo library and it will count how many white pixels there are. There are three implementations of this counting algorithm:

  1. Simple, single-threaded, nested for loop;
  2. Simple, multi-threaded implementation, replacing outer for loop with concurrentPerform; and
  3. A improved rendition of multi-threaded implementation that strides within concurrentPerform to try to balance amount of work done per thread (which is important in such a simple calculation).

See ImageProcessor.swift for these three renditions.

Developed in Swift on Xcode 11.1 and Swift 5. But the basic ideas are equally applicable for different versions of Swift.

License

Copyright © 2019 Robert Ryan. All rights reserved.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

--

23 October 2019