#!/bin/bash

# This is a bash script for a ktimetracker benchmark - how fast is ktimetracker on your system ?
# example: my 2.4GHz Quad-core X64 computer with 4GB RAM needs 50 seconds

# preparation
killall ktimetracker
rm /tmp/ktimetrackerbenchmark.ics 2>&1 | grep -v "no such file or directory"

time(

  # start ktimetracker and make sure its dbus interface is ready
  ktimetracker /tmp/ktimetrackerbenchmark.ics &
  while (! qdbus | grep ktimetracker ) do i=5; done
  ktimetrackerprocess=$(qdbus|grep ktimetracker)
  for n in $(seq 1 1 2)
  do 
    # add 300 tasks
    for i in $(seq 1 1 300)
    do qdbus $ktimetrackerprocess /KTimeTracker addTask task$n-$i
      qdbus $ktimetrackerprocess /KTimeTracker org.kde.ktimetracker.ktimetracker.startTimerFor $(qdbus $ktimetrackerprocess /KTimeTracker org.kde.ktimetracker.ktimetracker.taskIdsFromName task$n-$i);
    done 
    qdbus $ktimetrackerprocess /KTimeTracker org.kde.ktimetracker.ktimetracker.saveAll
    qdbus $ktimetrackerprocess /KTimeTracker org.kde.ktimetracker.ktimetracker.stopAllTimersDBUS
  done 
)
