Repository navigation
Home
João Medeiros edited this page Apr 10, 2023
·
47 revisions
SYNOPSIS
#include <time.h>
int clock_gettime(clockid_t clockid, struct timespec *tp);struct timespec {
time_t tv_sec; /* seconds */
long tv_nsec; /* nanoseconds */
};#include <stdio.h>
#include <time.h>
#include <unistd.h>
int main(int argc, char **argv)
{
struct timespec a, b;
unsigned int t;
clock_gettime(CLOCK_MONOTONIC, &b);
sleep(1);
clock_gettime(CLOCK_MONOTONIC, &a);
t = (a.tv_sec * 1e9 + a.tv_nsec) - (b.tv_sec * 1e9 + b.tv_nsec);
printf("%u\n", t);
return 0;
}int search(int *v, unsigned int n, int k)
{
while (n-- > 0)
{
if (v[n] == k)
return n;
}
return -1;
}import time
if __name__ == "__main__":
b = time.time_ns()
time.sleep(1)
a = time.time_ns()
t = a - b
print(t)def search(v, k):
n = len(v)
while (n > 0):
n = n - 1
if v[n] == k:
return n
return -1import java.lang.System;
import java.lang.Thread;
public class Measure
{
public static void main(String[] args) throws InterruptedException
{
long a, b, t;
b = java.lang.System.nanoTime();
java.lang.Thread.sleep(1000);
a = java.lang.System.nanoTime();
t = (a - b);
java.lang.System.out.println(t);
}
}public class Measure
{
public static int search(ArrayList<Integer> v, int k)
{
int n = v.size();
while (n-- > 0)
{
if (v.get(n) == k)
return n;
}
return -1;
}
}use std::{thread, time};
fn main()
{
let duration = time::Duration::from_secs(1);
let now = time::Instant::now();
thread::sleep(duration);
let measure = now.elapsed();
println!("{}", measure.as_nanos());
}fn search(v: &mut Vec<i32>, k: i32) -> i32
{
let mut n = v.len();
while n > 0
{
n = n - 1;
if v[n] == k
{
return n as i32;
}
}
return -1;
}