Beispiel #1
0
int main(int argc, char* argv[])
{
	#ifdef MEMORY_TEST_INCLUDED
	// Memory used BEFORE creating LinkedList
	long m1 = getMemoryUsage();
	#endif

	if (argc != 2)
	{
		printf("Usage: %s <number of elements to add>\n", argv[0]);
		return 1;
	}

	struct LinkedList* list = linkedListCreate(); 
	int numElements = atoi(argv[1]);
	for (int i = 1 ; i <= numElements; i++)
	{
		linkedListAddBack(list, (TYPE)i);
		linkedListRemoveFront(list);
	}

	linkedListAddBack(list, (TYPE)10);
        linkedListPrint(list);

	#ifdef MEMORY_TEST_INCLUDED
	// Memory used AFTER creating LinkedList
	long m2 = getMemoryUsage();
	printf("Memory used by LinkedList: %ld KB \n", m2 - m1);
	#endif

	double t1 = getMilliseconds(); // Time before contains()
	for (int i = 0; i < numElements; i++)
	{
		linkedListContains(list, i);
	}
	double t2 = getMilliseconds(); // Time after contains()
	printf("Time for running contains() on %d elements: %g ms\n", numElements, t2 - t1);

	linkedListDestroy(list);

	return 0;
}
int main(int argc, char* argv[]) {	
	DynArr* b;
	int n, i;
	double t1, t2;
	#ifdef MEMORY_TEST_INCLUDED
	/* variables to hold memory used before and after creating DynArr */	
	long m1, m2;
	/* memory used BEFORE creating DynArr */
	m1 = getMemoryUsage();
	#endif

	if( argc != 2 ) return 0;
	  
	b = createDynArr(1000); 
	n = atoi(argv[1]); /*number of elements to add*/
		
	for( i = 0 ; i < n; i++) {
		addDynArr(b, (TYPE)i); /*Add elements*/
	}		
	
	#ifdef MEMORY_TEST_INCLUDED
	/* memory used AFTER creating DynArr */
	m2 = getMemoryUsage();  
	printf("Memory used by DynArr: %ld KB \n", m2-m1);
	#endif
	
	t1 = getMilliseconds();/*Time before contains()*/
	
	for(i=0; i<n; i++) {
		containsDynArr(b, i);		
	}	
	
	t2 = getMilliseconds();/*Time after contains()*/
	
	printf("Time for running contains() on %d elements: %g ms\n", n, t2-t1);
  
	/* delete DynArr */
	deleteDynArr(b);
	
	return 0;
}
int main(int argc, char* argv[])
{
	#ifdef MEMORY_TEST_INCLUDED
	// Memory used BEFORE creating LinkedList
	long m1 = getMemoryUsage();
	#endif

	if (argc != 2)
	{
		printf("Usage: %s <number of elements to add>\n", argv[0]);
		return 1;
	}
	
	DynArr *a = newDynArr(1024);
	
	int numElements = atoi(argv[1]);
	int i;
	for (i = 0 ; i < numElements; i++)
	{
		addDynArr(a, (TYPE)i);
	}

	#ifdef MEMORY_TEST_INCLUDED
	// Memory used AFTER creating LinkedList
	long m2 = getMemoryUsage();
	printf("Memory used by Dynamic Array : %ld KB \n", m2 - m1);
	#endif

	double t1 = getMilliseconds(); // Time before contains()
	for (i = 0; i < numElements; i++)
	{
		containsDynArr(a, i);
	}
	double t2 = getMilliseconds(); // Time after contains()
	printf("Time for running contains() on %d elements: %g ms\n", numElements, t2 - t1);

	deleteDynArr(a);

	return 0;
}
Beispiel #4
0
void RemoteGoatVstAudioProcessor::writeTrace(const String& line)
{
	auto time = Time::getCurrentTime();
	String traceLine;
	traceLine << "[" << time.toString(false, true, true, true)
		<< ":" << time.getMilliseconds()
		<< "] " << line;

	_traceMutex.lock();
	{
		_trace.push_back(traceLine);

		if (_trace.size() > getTraceCountMaximum())
			_trace.pop_front();
	}
	_traceMutex.unlock();
}
Beispiel #5
0
  void Timer::print(FILE* out) const {
    unsigned long milliseconds = getMilliseconds();
    unsigned long seconds = milliseconds / 1000;
    unsigned long minutes = seconds / 60;
    unsigned long hours = minutes / 60;

    milliseconds %= 1000;
    seconds %= 60;
    minutes %= 60;

    fputc('(', out);
    if (hours != 0)
      fprintf(out, "%luh", hours);
    if (minutes != 0 || hours != 0)
      fprintf(out, "%lum", minutes);
    fprintf(out, "%lu.%03lus)", seconds, milliseconds);
  }
Beispiel #6
0
  void Timer::print(std::ostream& out) const {
    unsigned long milliseconds = getMilliseconds();
    unsigned long seconds = milliseconds / 1000;
    unsigned long minutes = seconds / 60;
    unsigned long hours = minutes / 60;

    milliseconds %= 1000;
    seconds %= 60;
    minutes %= 60;

    if (hours != 0)
      out << hours << 'h';
    if (minutes != 0 || hours != 0)
      out << minutes << 'm';
    out << seconds << '.';
    out << (milliseconds / 100);
    out << ((milliseconds / 10) % 10);
    out << (milliseconds % 10);
    out << "s";
  }
Beispiel #7
0
double Timer::getSeconds(void) 
{
	return ((double)getMilliseconds())/1000.0;
}
Beispiel #8
0
void SimpQEM::simplify(int goal, int gridres=1)
{

  cerr << "Initializing edge costs.\n";
  time_updating = 0;
  time_collapsing = 0;
  time_skipping = 0;
  time_resetting = 0;
  time_iterating = 0;
  failed_pop = 0;
  failed_removed = 0;
  failed_cost = 0;
  edges_outdated = 0;
  unsigned long time_grid = 0;
  timespec t0,t1,t,tu,tu0,tu1;
  timespec tr0,tr1,tr; //time for resetting queue
  timespec tgrid0,tgrid1,tgrid;//Time for constructing grid
  clock_gettime(CLOCK_REALTIME, &t0);
  initQuadrics();
  initEdgeCosts();
  clock_gettime(CLOCK_REALTIME, &t1);
  t = diff(t0,t1);
  cout << greentty << "Time_init_edges: " << getMilliseconds(t) << deftty << endl;
  int vertices_removed = 0;
  cerr << orangetty<< "Target vertex count: " << s->m_points.size() - goal << deftty<< endl;

  clock_gettime(CLOCK_REALTIME, &t0);
  while(vertices_removed < goal)
  {
    clock_gettime(CLOCK_REALTIME,&tgrid0);
    initUniformGrid(gridres);
    clock_gettime(CLOCK_REALTIME,&tgrid1);
    tgrid = diff(tgrid0,tgrid1);
    time_grid += getNanoseconds(tgrid);
    cout << greentty << "Grid: " << gridres << endl;
    cout << lightcyantty << "Removed: " << vertices_removed << endl;
    cout << lightgreentty << "Time_init_grid: " << getMilliseconds(tgrid) << deftty << endl;


    omp_set_num_threads(nthreads);

    #pragma omp parallel for
    for(int i = 0; i < n_cells; ++i)
    {
      int vr = 0;
      if(cell[i].empty() || cell_queue[i].empty()) continue;

      //cerr << "Simplifying cell " << i << " - " << cell_queue[i].size() << " edges" <<  endl;

      while(vr < initial_vertices[i]/gridres && vertices_removed < goal && !cell_queue[i].empty())
      {

        Edge e = cell_queue[i].top();
        cell_queue[i].pop();

        //Skip edge if it's been removed or its cost has changed.
        if(s->is_edge_removed[e.id] || e.cost != currentEdgeCost[e.id] || e.p1->faces.empty() || e.p2->faces.empty())
        {
            //failed_pop++;
            continue;
        }

        double tempQ[4][4];
        copyQuadrics(tempQ,e.p1->Q);
        sumQuadrics(tempQ,e.p2->Q);
        bool collapsed = s->collapse(e);
        if(collapsed)
        {

          copyQuadrics(e.p2->Q,tempQ);
          vr++;
          clock_gettime(CLOCK_REALTIME,&tu0);
          updateEdgeCosts(e.p2, i);
          clock_gettime(CLOCK_REALTIME,&tu1);
          tu = diff(tu0,tu1);
          time_updating += getNanoseconds(tu);
          currentEdgeCost[e.id] = INF; // Edge has been removed
          #pragma omp atomic
          vertices_removed++;
        }
      }
      //cerr << "Vertices removed: " << vr << endl;
    }
    if(gridres>=2) gridres/=2;
  }

  clock_gettime(CLOCK_REALTIME, &t1);
  t = diff(t0,t1);


  cout << bluetty << "Time_simplify: " << getNanoseconds(t)/1000000 << deftty << endl;
  cout << bluetty << "Time_updating: " << time_updating/1000000 << deftty << endl;
  cout << yellowtty << "Time_get_error: " << time_error/1000000 << deftty << endl;
  cout << lightbluetty << "Time_quadrics: " << time_quadrics/1000000 << deftty << endl;
  cout << lightpurpletty << "Time_other: " << time_other/1000000 << deftty << endl;
  // cout << yellowtty << "Time_iterating: " << time_iterating/1000000 << deftty << endl;
  // cout << lightbluetty << "Time_collapsing: " << time_collapsing/1000000 << deftty << endl;
  // cout << lightpurpletty << "\tRemoving faces: " << s->time_faces/1000000 << deftty<<endl;
  // cout << lightpurpletty << "\tRemoving edges: " << s->time_edges/1000000 << deftty<<endl;
  // cout << lightpurpletty << "\tRemoving points: " << s->time_point/1000000 << deftty<<endl;
  // cout << redtty << "Time skipping: " << time_skipping/1000000 << deftty << endl;
  // cout << cyantty << "Time resetting queue: " << time_resetting/1000000 << deftty << endl;
  // cout << lightredtty << "Failed pops: " << failed_pop << " " << failed_removed << "(removed) - " << failed_cost << "(cost)" << deftty<<endl;
  // cout << lightredtty << "Failed collapses: " << s->failed_collapses << deftty << endl;
  cout << cyantty << "Left in queue: " << edge_queue.size() << deftty << endl;
}
Beispiel #9
0
int main(int argc, char **argv)
{
  nonportFail = testingFail;

  char s[4];
  s[0] = '-';
  s[1] = 'l';
  s[2] = 's';
  s[3] = 0;
  if (0!=strcmp(s, "-ls")) {
    printf("strcmp failed!\n");
    return 4;
  }

  // process arguments
  bool interactive = false;
  for (int i=1; i<argc; i++) {
    if (0==strcmp("-ls", argv[i])) {
      // do an ls, and bail
      applyToCwdContents(printIt);
      return 0;
    }
    else if (0==strcmp("-noninteractive", argv[i])) {
      // don't do the interactive stuff
      interactive = false;
    }
    else {
      printf("unknown option: %s\n", argv[i]);
      return 2;
    }
  }

  // trying to figure out why backspace sometimes gives ^? crap
  // (turns out Konsole sometimes sends ^? in response to BS,
  // even when the option looks unchecked)
  //char buf[80];
  //printf("type stuff and try backspace: ");
  //gets(buf);
  //printf("%s (%d chars)\n", buf, strlen(buf));
  //return 0;

  long startTime = getMilliseconds();

  if (interactive) {
    printf("Type some characters; you should see each\n"
	   "character echoed once as you type it (q to stop):\n");
    setRawMode(true);
    char ch;
    do {
      ch = getConsoleChar();
      printf("%c", ch);
    } while (ch != 'q');

    setRawMode(false);

    printf("\n\nYou typed for %ld milliseconds\n",
	   getMilliseconds() - startTime);
  }

  limitFileAccess("chmod.test");

  printf("if the current dir contains a file called "
         "chmod.test, I just attempted to limit\n"
         "its access to just the owner\n");

  createDirectory("test.dir");

  // test chdir, which also implicitly tests mkdir
  bool didFirst=false;
  if (!changeDirectory("test.dir") || (didFirst=true, false) ||
      !changeDirectory("..")) {
    printf("failed while trying to chdir to %s\n",
           (didFirst? ".." : "test.dir"));
  }

  // more straightforward
  if (!fileOrDirectoryExists("test.dir")) {
    printf("test.dir didn't get created?\n");
  }

  printf("what's more, I just tried to mkdir & chdir test.dir\n");

  // test ensurePath
  if (!ensurePath("test.dir/a/b/c/d", false /*isDirectory*/)) {
    printf("ensurePath test.dir/a/b/c/d failed\n");
  }

  // try to list partial directory contents
  printf("listing of first 10 files in this directory:\n");
  {
    int count = 0;
    applyToCwdContents(printFirst10, &count);
  }

  // test date function
  {
    int m, d, y;
    getCurrentDate(m, d, y);

    printf("I think the date is (m/d/yyyy): %d/%d/%d\n",
           m, d, y);
  }

  // test sleep (mostly just to make sure it doesn't segfault)
  printf("sleeping for 1 second...\n");
  portableSleep(1);

  // test user name
  char buf[80];
  getCurrentUsername(buf, 80);
  printf("current user name is: %s\n", buf);

  if (interactive) {
    // test nonecho reading
    printf("Type something and press Enter; it won't be echoed (yet):\n");
    readNonechoString(buf, 80, "  > ");
    printf("You typed: %s\n", buf);
  }

  // test random stuff
  printf("hasSystemCryptoRandom: ");
  if (!hasSystemCryptoRandom()) {
    printf("no\n");
  }
  else {
    printf("yes\n");

    printf("three random numbers: %u %u %u\n",
           getSystemCryptoRandom(),
           getSystemCryptoRandom(),
           getSystemCryptoRandom());
  }

  printf("testing nprintf...\n");
  nprintfVector("simple");
  nprintfVector("a %s more", "little");
  nprintfVector("some %4d more %s complicated %c stuff",
                33, "yikes", 'f');
  nprintfVector("%f", 3.4);

  printf("nonport works\n");
  return 0;
}
Beispiel #10
0
jlong sysTimeMillis(void) {
    jlong res = getMilliseconds();
    return res;
}
Beispiel #11
0
 int64_t getSeconds() const
 {
     return int64_t(0.5 + getMilliseconds() / 1000.0);
 }
Beispiel #12
0
Time::Time(const std::string& str, const std::string& fmt)
: _msecs(0)
{
  unsigned hours = 0;
  unsigned minutes = 0;
  unsigned seconds = 0;
  unsigned mseconds = 0;
  bool am = true;

  enum {
    state_0,
    state_fmt
  } state = state_0;

  std::string::const_iterator dit = str.begin();
  std::string::const_iterator it;
  for (it = fmt.begin(); it != fmt.end(); ++it)
  {
    char ch = *it;
    switch (state)
    {
      case state_0:
        if (ch == '%')
          state = state_fmt;
        else
        {
          if (dit == str.end() || *dit != ch)
            throw std::runtime_error("string <" + str + "> does not match time format <" + fmt + '>');
          ++dit;
        }
        break;

      case state_fmt:
        switch (ch)
        {
          case 'H':
          case 'I':
            hours = getUnsigned(dit, str.end(), 2);
            break;

          case 'M':
            minutes = getUnsigned(dit, str.end(), 2);
            break;

          case 'S':
            seconds = getUnsigned(dit, str.end(), 2);
            break;

          case 'j':
            if (dit != str.end() && *dit == '.')
              ++dit;
            mseconds = getMilliseconds(dit, str.end());
            break;

          case 'J':
          case 'K':
            if (dit != str.end() && *dit == '.')
            {
              ++dit;
              mseconds = getMilliseconds(dit, str.end());
            }
            break;

          case 'k':
            mseconds = getMilliseconds(dit, str.end());
            break;

          case 'p':
            if (dit == str.end()
              || dit + 1 == str.end()
              || ((*dit != 'A'
                && *dit != 'a'
                && *dit != 'P'
                && *dit != 'p')
              || (*(dit + 1) != 'M'
                &&  *(dit + 1) != 'm')))
            {
                throw std::runtime_error("string <" + str + "> does not match time format <" + fmt + '>');
            }

            am = (*dit == 'A' || *dit == 'a');
            dit += 2;
            break;

          default:
            throw std::runtime_error("invalid time format <" + fmt + '>');
        }

        state = state_0;
        break;
    }
  }

  if (it != fmt.end() || dit != str.end())
    throw std::runtime_error("string <" + str + "> does not match time format <" + fmt + '>');

  set(am ? hours : hours + 12, minutes, seconds, mseconds);
}