I would like to know if you can measure execution time in nanoseconds - I have the following source code, however the time is measured in milliseconds. Help If You May !

#include <stdlib.h>
#include <stdio.h>
#include <windows.h>

#define NUM_ITEMS 500000

void quickSort(int numbers[], int array_size);
void q_sort(int numbers[], int left, int right);

int numbers[NUM_ITEMS];

int main()
  int i;
  int con;
  int k;
  long te, ts;

  //seed random number generator

  //fill array with random integers
  for (k = 0; k < NUM_ITEMS; k++)
  numbers[k] = rand();

ts = GetTickCount();

  //perform quick sort on array
  quickSort(numbers, NUM_ITEMS);
te = GetTickCount();

printf("Bubble sort of 5000 random integers took %d ms\n", te - ts);

 getchar(); // wait
 return 0;

void quickSort(int numbers[], int array_size)
  q_sort(numbers, 0, array_size - 1);

void q_sort(int numbers[], int left, int right)
  int pivot, l_hold, r_hold;

  l_hold = left;
  r_hold = right;
  pivot = numbers;
  while (left < right)
    while ((numbers >= pivot) && (left < right))
    if (left != right)
      numbers = numbers;
    while ((numbers <= pivot) && (left < right))
    if (left != right)
      numbers = numbers;
  numbers = pivot;
  pivot = left;
  left = l_hold;
  right = r_hold;
  if (left < pivot)
    q_sort(numbers, left, pivot-1);
  if (right > pivot)
    q_sort(numbers, pivot+1, right);

>>I would like to know if you can measure execution time in nanoseconds
No. milliseconds is probably the best you can achieve. If you are using MS-Windows you MIGHT be able to use QueryPerformanceFrequency()

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.