Jump to content

Verificare eficienta cod


Stefan

Recommended Posts

Pentru măsurarea timpului de execuție se poate adapta următorul cod după nevoi:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
	clock_t start, finish;
	long loop;
	double result, r2, elapsed_time;
	printf("Inmultirea a doua numere reale de un miliard de ori...\n");
	result = 3.1415926535897;
	start = clock(); //inceputul experimentului
	for (loop = 0; loop < 1000000000; loop++) {
		r2 = result*16.0;
	}
	finish = clock(); //sfarsitul operatiilor cronometrate
	elapsed_time = (double)(finish - start) / CLOCKS_PER_SEC;
	printf("\nProgramul necesita %6.2f secunde.\n", elapsed_time);
	return 0;
}

Pentru eficiență ca spațiu de memorie ocupat: https://stackoverflow.com/questions/10443131/how-much-memory-a-c-c-program-is-using

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.