Created
September 26, 2018 16:36
-
-
Save ladislas/7316f848367c3ee76060f71c7ffcd0c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.swift | |
// Test | |
// | |
// Created by Ladislas de Toldi on 29/08/2018. | |
// | |
//: Playground - noun: a place where people can play | |
import Darwin | |
import Schedule | |
/* | |
var t = Timer() | |
t.start() | |
// do something | |
t.stop() | |
println("took \(t.seconds)") | |
*/ | |
/* | |
var t = Timer() | |
t.start() | |
// do something | |
t.stop() | |
print("took \(t.seconds)") | |
*/ | |
struct Timer { | |
var startTime: UInt64 = 0 | |
var stopTime: UInt64 = 0 | |
let numer: UInt64 | |
let denom: UInt64 | |
init() { | |
var info = mach_timebase_info(numer: 0, denom: 0) | |
mach_timebase_info(&info) | |
numer = UInt64(info.numer) | |
denom = UInt64(info.denom) | |
} | |
func getInfo() { | |
print(numer) | |
print(denom) | |
} | |
mutating func start() { | |
startTime = mach_absolute_time() | |
} | |
mutating func stop() { | |
stopTime = mach_absolute_time() | |
} | |
var nanoseconds: UInt64 { | |
return ((stopTime - startTime) * numer) / denom | |
} | |
var microseconds: Double { | |
return Double(nanoseconds) / 1_000 | |
} | |
var milliseconds: Double { | |
return Double(nanoseconds) / 1_000_000 | |
} | |
var seconds: Double { | |
return Double(nanoseconds) / 1_000_000_000 | |
} | |
} | |
var t = Timer() | |
//t.init() | |
//t.start() | |
Schedule.after(0.100.second).do { | |
// t.stop() | |
print("Hello") | |
// print("\(t.milliseconds) second passed!") | |
} | |
// | |
//Schedule.after(1.minute, repeating: 0.5.seconds).do { | |
// print("Ping!") | |
//} | |
// | |
//Schedule.every("one minute and ten seconds").do { | |
// print("One minute and ten seconds elapsed!") | |
//} | |
// | |
//Schedule.every(.monday, .tuesday, .wednesday, .thursday, .friday).at(6, 30).do { | |
// print("Get up!") | |
//} | |
// | |
//Schedule.every(.june(14)).at("9:30").do { | |
// print("Happy birthday!") | |
//} | |
// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment