I need to load in memory a lot of different info, and I want to know which way is faster: simple tsv file, or realm database.
For that I'm trying to implement scheduled timer in AppDelegate. This timer should start as soon as possible, and it should stop when the data is loaded.
I created some small class for that, with internal counter:
class TimerSpeedCounter {
var timer: Timer!
var counter: Int = 0
init() {
self.counterInit()
}
func counterInit() {
self.counter = 0
self.timer = Timer.scheduledTimer(timeInterval: 0.01, target: self, selector: #selector(TimerSpeedCounter.countPlusOne), userInfo: nil, repeats: true)
}
@objc func countPlusOne() {
self.counter = self.counter + 1
}
I'm creating this TimerSpeedCounter in didFinishLaunchingWithOptions
, and this is singleton. I put it at the beginning:
timerSpeed.counterInit()
Obviously I want to see the value of self.counter
when my function that loads all the data stops.
The thing is, it somehow works, but self.counter
is always equals zero, because this timer is fired much later than needed (after these functions load all the data).
So, I have two questions.
What am I doing wrong? Why this timer is fired much later than it should?
What is the right way to compare the speed of two different solutions?