Real-world time management and scheduling.
// benchmark.ifa - Measure code execution time
ise benchmark(name, iterations, func) {
Irosu.fo("Benchmarking: " + name);
// Warm-up run
func();
// Timed runs
ayanmo times = [];
ayanmo i = 0;
nigba (i < iterations) {
ayanmo start = Iwori.now_ns();
func();
ayanmo elapsed = Iwori.now_ns() - start;
ayanmo times = Ogunda.push(times, elapsed);
ayanmo i = i + 1;
}
// Calculate statistics
ayanmo total = Osa.sum(times);
ayanmo avg = total / iterations;
ayanmo min = Osa.min(times);
ayanmo max = Osa.max(times);
Irosu.fo(" Iterations: " + iterations);
Irosu.fo(" Avg: " + (avg / 1000000) + " ms");
Irosu.fo(" Min: " + (min / 1000000) + " ms");
Irosu.fo(" Max: " + (max / 1000000) + " ms");
padap? {"avg": avg, "min": min, "max": max};
}
// Usage
benchmark("Fibonacci", 100, || {
ise fib(n) {
ti (n <= 1) { padap? n; }
padap? fib(n - 1) + fib(n - 2);
}
fib(20);
});
benchmark("List operations", 1000, || {
ayanmo list = [];
ayanmo i = 0;
nigba (i < 100) {
ayanmo list = Ogunda.push(list, i);
ayanmo i = i + 1;
}
});
// scheduler.ifa - Run tasks at specific times
ayanmo tasks = [];
ise schedule(name, interval_ms, func) {
ayanmo tasks = Ogunda.push(tasks, {
"name": name,
"interval": interval_ms,
"last_run": 0,
"func": func
});
}
ise run_scheduler() {
Irosu.fo("Scheduler started at " + Iwori.format(Iwori.now(), "%H:%M:%S"));
nigba (otito) {
ayanmo now = Iwori.now_ms();
fun task ninu tasks {
ayanmo elapsed = now - task["last_run"];
ti (elapsed >= task["interval"]) {
Irosu.fo("[" + Iwori.format(Iwori.now(), "%H:%M:%S") + "] Running: " + task["name"]);
task["func"]();
task["last_run"] = now;
}
}
Oyeku.sleep(100); // Check every 100ms
}
}
// Usage
schedule("Health check", 5000, || {
Irosu.fo(" ? System healthy");
});
schedule("Sync data", 10000, || {
Irosu.fo(" ? Data synced");
});
schedule("Cleanup temp files", 30000, || {
Irosu.fo(" ? Temp files cleaned");
});
run_scheduler();
// timezone.ifa - Convert between time zones
ayanmo TIMEZONES = {
"UTC": 0,
"EST": -5,
"PST": -8,
"CET": 1,
"JST": 9,
"WAT": 1,
"IST": 5.5
};
ise convert_timezone(timestamp, from_tz, to_tz) {
ayanmo from_offset = TIMEZONES[from_tz];
ayanmo to_offset = TIMEZONES[to_tz];
ti (from_offset == nil || to_offset == nil) {
padap? Okanran.error("Unknown timezone");
}
// Convert to UTC first, then to target
ayanmo utc = timestamp - (from_offset * 3600);
ayanmo result = utc + (to_offset * 3600);
padap? result;
}
ise format_local_time(timestamp, tz) {
ayanmo formatted = Iwori.format(timestamp, "%Y-%m-%d %H:%M:%S");
padap? formatted + " " + tz;
}
// Usage
ayanmo now = Iwori.now();
Irosu.fo("Current time around the world:");
Irosu.fo("-----------------------------");
fun tz key(TIMEZONES) {
ayanmo local = convert_timezone(now, "UTC", tz);
Irosu.fo(tz + ": " + format_local_time(local, tz));
}
// countdown.ifa - Calculate time until events
ise time_until(target_date) {
ayanmo now = Iwori.now();
ayanmo diff = target_date - now;
ti (diff <= 0) {
padap? {"expired": otito};
}
ayanmo days = Oturupon.div(diff, 86400);
ayanmo hours = Oturupon.div(Oturupon.mod(diff, 86400), 3600);
ayanmo mins = Oturupon.div(Oturupon.mod(diff, 3600), 60);
ayanmo secs = Oturupon.mod(diff, 60);
padap? {
"expired": iro,
"days": days,
"hours": hours,
"minutes": mins,
"seconds": secs
};
}
ise format_countdown(remaining) {
ti (remaining["expired"]) {
padap? "Event has passed!";
}
padap? remaining["days"] + "d " +
remaining["hours"] + "h " +
remaining["minutes"] + "m " +
remaining["seconds"] + "s";
}
// Usage
ayanmo events = [
{"name": "New Year 2027", "date": Iwori.parse("2027-01-01 00:00:00")},
{"name": "Summer Solstice", "date": Iwori.parse("2026-06-21 00:00:00")},
{"name": "Product Launch", "date": Iwori.parse("2026-03-15 09:00:00")}
];
Irosu.fo("? Event Countdowns");
Irosu.fo("------------------");
fun event ninu events {
ayanmo remaining = time_until(event["date"]);
Irosu.fo(event["name"] + ": " + format_countdown(remaining));
}