Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > C/C++ программирование > Общие вопросы C/C++
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 13.12.2009, 13:22   #1
Solncelikiy
Пользователь
 
Регистрация: 08.10.2009
Сообщений: 14
По умолчанию Подсчет времени работы алгоритмов

Здравствуйте
нужно посчитать время выполнения перемножения больших матриц несколькими способами, пытался организовать подсчет через таймер но что-то не получается, таймер упорно выдает для всех алгоритмов одно и то же значение, порядка 1сек, хотя считает на самом деле намного больше.
мой код
Код:
#include "stdafx.h"
#include <ctime>
#include <stdlib.h>
#include <time.h>
#include "Math.h"
#pragma once



//int k1[10000];
//int k2[10000];
//float t=0,t1=0;
namespace Metod1 {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for Form1
	///
	/// WARNING: If you change the name of this class, you will need to change the
	///          'Resource File Name' property for the managed resource compiler tool
	///          associated with all .resx files this class depends on.  Otherwise,
	///          the designers will not be able to interact properly with localized
	///          resources associated with this form.
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Button^  button1;
	private: System::Windows::Forms::ListBox^  listBox1;
	private: System::Windows::Forms::Button^  button2;
	private: System::Windows::Forms::Timer^  timer1;
	private: System::Windows::Forms::Timer^  timer2;
	private: System::ComponentModel::IContainer^  components;
	protected: 

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>


#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->components = (gcnew System::ComponentModel::Container());
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->listBox1 = (gcnew System::Windows::Forms::ListBox());
			this->button2 = (gcnew System::Windows::Forms::Button());
			this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
			this->timer2 = (gcnew System::Windows::Forms::Timer(this->components));
			this->SuspendLayout();
			// 
			// button1
			// 
			this->button1->Location = System::Drawing::Point(12, 139);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(91, 23);
			this->button1->TabIndex = 0;
			this->button1->Text = L"1000х1000";
			this->button1->UseVisualStyleBackColor = true;
			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// listBox1
			// 
			this->listBox1->FormattingEnabled = true;
			this->listBox1->Location = System::Drawing::Point(12, 12);
			this->listBox1->Name = L"listBox1";
			this->listBox1->Size = System::Drawing::Size(393, 121);
			this->listBox1->TabIndex = 1;
			// 
			// button2
			// 
			this->button2->Location = System::Drawing::Point(109, 139);
			this->button2->Name = L"button2";
			this->button2->Size = System::Drawing::Size(92, 23);
			this->button2->TabIndex = 2;
			this->button2->Text = L"5000х5000";
			this->button2->UseVisualStyleBackColor = true;
			// 
			// timer1
			// 
			this->timer1->Enabled = true;
			this->timer1->Interval = 10;
			this->timer1->Tick += gcnew System::EventHandler(this, &Form1::timer1_Tick);
			// 
			// timer2
			// 
			this->timer2->Enabled = true;
			this->timer2->Interval = 10;
			this->timer2->Tick += gcnew System::EventHandler(this, &Form1::timer2_Tick);
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(417, 165);
			this->Controls->Add(this->button2);
			this->Controls->Add(this->listBox1);
			this->Controls->Add(this->button1);
			this->Name = L"Form1";
			this->Text = L"Form1";
			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
			this->ResumeLayout(false);

		}
#pragma endregion
	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
			 }
Solncelikiy вне форума Ответить с цитированием
Старый 13.12.2009, 13:23   #2
Solncelikiy
Пользователь
 
Регистрация: 08.10.2009
Сообщений: 14
По умолчанию

продолжение кода
Код:
void zap(double *a, int n)//-Заполняем массив 
	{	
		srand(time(NULL));	
		for (int i=0; i < n; i++)
			for (int j=0; j < n; j++)
			 a[i*n+j]=rand() % 100;
		listBox1->Items->Add("ok");
	}

	void met1(double *a, double *b, double *c, int n)//-первый метод
	{
		int i, j, m;
		double *pa, *pb, *pc, s;
		for (m=0, pc=c; m<n; m++)
			for (i = 0, pb=b; i < n; i++, pb++)
			  {
			for (s=0, j=0, pa=a+m*n; j<n; j++)
				  s+=*(pa++)*pb[j*n];
			 *(pc++)=s;
			  }
		listBox1->Items->Add("ok");
}

	void met2(double *a, double *b, double *c, int n)//-второй метод
	{
		int i, j, m;
		double *pa, *pb, *pc, s;
		for (m=0, pc=c; m<n; m++, pc++)
			for (i = 0, pa=a, pb=b+m; i < n; i++)
			 {
			for (s=0, j=0; j<n; j++)
				  s+=*(pa++)*pb[j*n];
			 pc[i*n]=s;
			 }
		listBox1->Items->Add("ok");
	}

	void met3(double *a, double *b, double *c, int n)//-третий метод
	{ 
		int i, j, m, bm, bi, nbm, nbi, N=10;
		double *pa, *pb, *pc, s;
		for (bm=0; bm<n; bm += N)
			{
			nbm=(bm+N<=n ? bm+N:n);
			for (bi = 0; bi<n; bi+=N)
				{
				nbi=(bi+N<=n ? bi+N:n);
				for (m=bm, pc=c+bm; m<nbm; m++, pc++)
					for (i=bi, pa=a+bi*n, pb=b+m; i<nbi; i++)
					{
					for (s=0, j=0; j<n; j++)
					s+=*(pa++)*pb[j*n];
					pc[i*n]=s;
					}
				}
			}
		listBox1->Items->Add("ok");
	}

	void met4(double *a, double *b, double *c, int n)//-четвертый метод
	{
		int i, j, m, nl, bm, bi, nbm, nbi, N=10, l;
		double *pa, *pb, *pc, s;
		for (bm=0; bm<n; bm+=N)
		{
			nbm=(bm+N<=n ? bm+N:n);
			for (bi = 0; bi<n; bi+=N)
			{
				nbi=(bi+N<=n ? bi+N:n);
				for (m=bm, pc=c+bm; m<nbm; m++, pc++)
					for (i=bi; i<nbi; i++)
						pc[i*m]=0;
				for(l=0; l<n; l+=N)
				{
					nl=(l+N<=n ? l+N:n);
					for (m=bm, pc=c+bm; m<nbm; m++, pc++)
						for (i=bi, pb=b+m; i<nbi; i++)
						{
							pa=a+l+i*n;
							for (s=0, j=l; j<nl; j++)
								s+=*(pa++)*pb[j*n];
							pc[i*n]+=s;
						}
				}
			}
		}
		listBox1->Items->Add("ok");
	}

	void met5(double *a, double *b, double *c, int n)//-пятый метод
	{
		int i, j, m, nl, bm, bi, nbm, nbi, N=10, l;
		double *pa, *pb, *pc, s00, s01, s10, s11;
		for (bm=0; bm<n; bm+=N)
		{
			nbm=(bm+N<=n ? bm+N:n);
			for (bi = 0; bi<n; bi+=N)
			{
				nbi=(bi+N<=n ? bi+N:n);
				for (m=bm, pc=c+bm; m<nbm; m++, pc++)
					for (i=bi; i<nbi; i++)
						pc[i*m]=0;
				for(l=0; l<n; l+=N)
				{
					nl=(l+N<=n ? l+N:n);
					for (m=bm, pc=c+bm; m<nbm; m+=2, pc+=2)
						for (i=bi, pb=b+m; i<nbi; i+=2)
						{
							pa=a+l+i*n;
							s00=s01=s10=s11=0;
							for (j=l; j<nl; j++, pa++)
							{
								s00+=pa[0]*pb[j*n];
								s01+=pa[0]*pb[j*n+1];
								s10+=pa[n]*pb[j*n];
								s11+=pa[0]*pb[j*n+1];
							}
							pc[i*n]+=s00;
							pc[i*n+1]+=s01;
							pc[(i+1)*n]+=s10;
							pc[(i+1)*n+1]+=s11;
						}
				}
			}
		}
		listBox1->Items->Add("ok");
	}

	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) 
			 {	 listBox1->Items->Clear();	
		//		 timer1->Enabled=true;
				 listBox1->Items->Add("Начало перемножения матриц 1000х1000");
				 listBox1->Items->Add("Забиваем матрицы числами");
				 double *pa = new double[1000000];
				 double *pb = new double[1000000];
				 //-Заполнение массивов
				 zap(pa,1000);
				 zap(pb,1000);
				 double *pc = new double[1000000];
				 listBox1->Items->Add("Матрицы забиты числами, это заняло "+t/100+"сек");
			//	 t=0;
				 listBox1->Items->Add(" ");
				 listBox1->Items->Add("Собственно перемножаем первым способом");
				 met1(pa,pb,pc,1000);
				 listBox1->Items->Add("Перемножение первым способом заняло "+t/100+"сек");	
		//		 t=0;
				 listBox1->Items->Add(" ");
				 listBox1->Items->Add("Перемножаем вторым способом");
				 met2(pa,pb,pc,1000);
				 listBox1->Items->Add("Перемножение вторым способом заняло "+t/100+"сек");	
		//		 t=0;
				 listBox1->Items->Add(" ");
				 listBox1->Items->Add("Перемножаем третьим способом");
				 met3(pa,pb,pc,1000);
				 listBox1->Items->Add("Перемножение третьим способом заняло "+t/100+"сек");	
		//		 t=0;
				 listBox1->Items->Add(" ");
				 listBox1->Items->Add("Перемножаем четвертым способом");
				 met4(pa,pb,pc,1000);
				 listBox1->Items->Add("Перемножение четвертым способом заняло "+t/100+"сек");	
		//		 t=0;
				 listBox1->Items->Add(" ");
				 listBox1->Items->Add("Перемножаем пятым способом");
				 met5(pa,pb,pc,1000);
				 listBox1->Items->Add("Перемножение пятым способом заняло "+t/100+"сек");	
		//		 t=0;
				 listBox1->Items->Add(" ");
				 listBox1->Items->Add("ура, конец");
				
				 //-Чистим
				 delete[] pa;
				 delete[] pb;
				 delete[] pc;
			 }
	private: System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e) 
			 {
	//			t++;
			 }
private: System::Void timer2_Tick(System::Object^  sender, System::EventArgs^  e) 
		 {
	//		 t1++;
		 }
};
}
Solncelikiy вне форума Ответить с цитированием
Старый 15.12.2009, 20:15   #3
Solncelikiy
Пользователь
 
Регистрация: 08.10.2009
Сообщений: 14
По умолчанию

видимо никто не поможет, да ?
Solncelikiy вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Схемы алгоритмов Lazio Фриланс 2 01.12.2009 17:25
Распределения работы по рабочим, по времени выполнения. Rhamzes Microsoft Office Excel 3 01.07.2009 15:04
Вычисление времени работы программы Monte-Kristo Паскаль, Turbo Pascal, PascalABC.NET 2 12.06.2009 13:25
Подсчет времени kostya.myit Microsoft Office Excel 4 11.06.2009 23:43