Exemplo n.º 1
0
int RunApplication(int argc, char * *argv)
{
	Console *console = new Console();

	/* Begin your application here. */

#ifdef ENABLE_CPUID

	CPUID *cpuid = new CPUID();

	console->SetColour(console->FG_RED | console->FG_INTENSITY);
	console->WriteLine("======================");
	console->WriteLine("= CPU IDENTIFICATION =");
	console->WriteLine("======================");
	console->SetColour(0);
	console->WriteLine();

	cpuid->Go();

	/* NOTES */
	/* The Virtual count is the number of processors that the operating system sees, */
	/* but does not take into account whether any of the processors counted are */
	/* hyperthreads, cores, or truly physical CPUs. */
	/* */
	/* If the Physical and Logical counts are equal, the number of Physical/Logical is the */
	/* core count, because it's a dual core system. */

	console->WriteLine("There are %d processors in the system (%d cores per package, %d logical per package).",
	                   cpuid->VirtualCount(),
	                   cpuid->CoresPerPackage(),
	                   cpuid->LogicalPerPackage());

	if (cpuid->VirtualCount() > 1 || cpuid->CoresPerPackage() > 1 || cpuid->LogicalPerPackage() > 1) {
		if (cpuid->CoresPerPackage() == cpuid->LogicalPerPackage())
			console->WriteLine("This is a multi-core system.");
		else if (cpuid->CoresPerPackage() > 1 && cpuid->LogicalPerPackage() > cpuid->CoresPerPackage())
			console->WriteLine("This is a hyperthreaded multi-core system.");
		else if (cpuid->CoresPerPackage() == 1 && cpuid->LogicalPerPackage() > 1)
			console->WriteLine("This is a hyperthreaded system.");

		if (cpuid->VirtualCount() > cpuid->LogicalPerPackage())
			console->WriteLine("This is a multi-processor system.");
	} else {
		console->WriteLine("This is a single processor system.");
	}

	/*
	 * v32 l8 = 32/8 = 4
	 * v4 l2 = 4/2 = 2
	 * v2 l2 = 2/2 = 1
	 * v1 l2 = 1/2 = 0.5
	 */
	double ratio = (double)cpuid->VirtualCount() / (double)cpuid->LogicalPerPackage();
	if ((int)ratio < 1) {
		console->WriteLine();
		console->SetColour(console->FG_YELLOW | console->FG_INTENSITY);
		console->WriteLine("WARNING: Expected at least 1 physical package, but detected %0.1lf. Are you\n"
		                   "running this under a hypervisor?", ratio);
		console->SetColour();
	}

	console->WriteLine();

	for (int i = 0; i < MAX_PROCESSORS; i++) {
		/* Go through each Virtual processor. */
		if (cpuid->proc[i]->Manufacturer != NULL) {
			/* Print out the manufacturer string */
			console->WriteLine("CPU[%d] Manufacturer: %s", i,
			                   cpuid->proc[i]->Manufacturer);

			/* Print out the CPU name string, if available. */
			if (strlen(cpuid->proc[i]->ProcessorName) > 0)
				console->WriteLine("CPU[%d] Name: %s", i,
				                   cpuid->proc[i]->ProcessorName);

			/* Print out Family/Model/Stepping info. */
			console->WriteLine("CPU[%d] Family: %d, Model: %d, Stepping: %d", i,
			                   cpuid->proc[i]->Family, cpuid->proc[i]->Model,
			                   cpuid->proc[i]->Stepping);

			/* Print out the CPU cache info. */
			if (cpuid->proc[i]->caches.size() > 0) {
				console->WriteLine("CPU[%d] Caches:", i);
				for (size_t j = 0; j < cpuid->proc[i]->caches.size(); j++) {
					if (cpuid->proc[i]->caches.valid(j))
						console->Write("  %s",
						               cpuid->proc[i]->caches.get(j));
				}

				console->WriteLine();
			}

			/* Print out CPU features (MMX, SSE, and so on). */
			console->Write("CPU[%d] Features: ", i);

			CrissCross::Data::DArray<const char *>                  *featureIDs =
			        cpuid->proc[i]->features.ConvertIndexToDArray();

			for (size_t i = 0; i < featureIDs->size(); i++) {
				if (featureIDs->valid(i))
					console->Write("%s ", featureIDs->get(i));
			}

			delete featureIDs;

			console->WriteLine();
			console->WriteLine();
		}
	}

	delete cpuid;

#else

	console->WriteLine("CPUID isn't supported on your platform or compiler.");

#endif

	/* End your application here. */

#ifdef TARGET_OS_WINDOWS
	system("pause");
#endif

	delete console;
	return 0;
}
Exemplo n.º 2
0
int main(int argc, char * *argv)
{
	Console *console = new Console();

	/* Begin your application here. */

	CrissCross::Data::DArray<char *> randomStrings;
	CrissCross::System::Stopwatch sw;

	console->SetColour(console->FG_RED | console->FG_INTENSITY);
	console->WriteLine("CheckMark");
	console->SetColour();
	console->WriteLine("A checksum (hashing) algorithm benchmark.");
	console->WriteLine();
	console->WriteLine("Note: {whatever}Marks are a measurement of how many %s\nof data were processed per second by a given hash.",
#ifdef TARGET_OS_NDSFIRMWARE
		"kilobytes");
#else
		"megabytes");
#endif
	console->WriteLine();

	/* Generate some data for checksum speed tests. */
	console->Write("Generating data... ");
	sw.Start();
	GenerateRandom(randomStrings);
	sw.Stop();
	console->WriteLine("%5.3lfs", sw.Elapsed());
	console->WriteLine();

	/* This variable just makes the compiler think */
	/* the data is being used somehow. */
	unsigned long killOptimization = 0;

	sw.Start();
	for (int r = 0; r < MAX_RUNS; r++)
		for (int i = 0; i < DATASET_SIZE; i++) {
			killOptimization = adler32(0, randomStrings.get(i), ENTRY_LENGTH);
		}

	sw.Stop();
	console->WriteLine("%8lu AdlerMarks",
	                   (unsigned long)((double)(DATASET_SIZE * MAX_RUNS) / sw.Elapsed()),
	                   killOptimization);

	sw.Start();
	for (int r = 0; r < MAX_RUNS; r++)
		for (int i = 0; i < DATASET_SIZE; i++) {
			killOptimization = crc32(randomStrings.get(i), ENTRY_LENGTH);
		}

	sw.Stop();
	console->WriteLine("%8lu CRCMarks",
	                   (unsigned long)((double)(DATASET_SIZE * MAX_RUNS) / sw.Elapsed()),
	                   killOptimization);

	CrissCross::Crypto::MD4Hash md4;
	sw.Start();
	for (int r = 0; r < MAX_RUNS; r++)
		for (int i = 0; i < DATASET_SIZE; i++)
			md4.Process(randomStrings.get(i), ENTRY_LENGTH);

	sw.Stop();
	console->WriteLine("%8lu MD4Marks",
	                   (unsigned long)((double)(DATASET_SIZE * MAX_RUNS) / sw.Elapsed()));

	CrissCross::Crypto::MD5Hash md5;
	sw.Start();
	for (int r = 0; r < MAX_RUNS; r++)
		for (int i = 0; i < DATASET_SIZE; i++)
			md5.Process(randomStrings.get(i), ENTRY_LENGTH);

	sw.Stop();
	console->WriteLine("%8lu MD5Marks",
	                   (unsigned long)((double)(DATASET_SIZE * MAX_RUNS) / sw.Elapsed()));

	CrissCross::Crypto::SHA1Hash sha1;
	sw.Start();
	for (int r = 0; r < MAX_RUNS; r++)
		for (int i = 0; i < DATASET_SIZE; i++)
			sha1.Process(randomStrings.get(i), ENTRY_LENGTH);

	sw.Stop();
	console->WriteLine("%8lu SHA1Marks",
	                   (unsigned long)((double)(DATASET_SIZE * MAX_RUNS) / sw.Elapsed()));

	CrissCross::Crypto::SHA256Hash sha256;
	sw.Start();
	for (int r = 0; r < MAX_RUNS; r++)
		for (int i = 0; i < DATASET_SIZE; i++)
			sha256.Process(randomStrings.get(i), ENTRY_LENGTH);

	sw.Stop();
	console->WriteLine("%8lu SHA256Marks",
	                   (unsigned long)((double)(DATASET_SIZE * MAX_RUNS) / sw.Elapsed()));

	CrissCross::Crypto::SHA512Hash sha512;
	sw.Start();
	for (int r = 0; r < MAX_RUNS; r++)
		for (int i = 0; i < DATASET_SIZE; i++)
			sha512.Process(randomStrings.get(i), ENTRY_LENGTH);

	sw.Stop();
	console->WriteLine("%8lu SHA512Marks",
	                   (unsigned long)((double)(DATASET_SIZE * MAX_RUNS) / sw.Elapsed()));

	CrissCross::Crypto::TigerHash tiger;
	sw.Start();
	for (int r = 0; r < MAX_RUNS; r++)
		for (int i = 0; i < DATASET_SIZE; i++)
			tiger.Process(randomStrings.get(i), ENTRY_LENGTH);

	sw.Stop();
	console->WriteLine("%8lu TigerMarks",
	                   (unsigned long)((double)(DATASET_SIZE * MAX_RUNS) / sw.Elapsed()));

	randomStrings.flushArray();
	console->WriteLine();

	/* End your application here. */

#ifdef TARGET_OS_WINDOWS
	system("pause");
#endif

	delete console;
	return 0;
}
Exemplo n.º 3
0
int main(int argc, char * *argv)
{
	Console *console = new Console();

	/* Begin your application here. */

#ifdef ENABLE_CPUID

	CPUID *cpuid = new CPUID();

	console->SetColour(console->FG_RED | console->FG_INTENSITY);
	console->WriteLine("======================");
	console->WriteLine("= CPU IDENTIFICATION =");
	console->WriteLine("======================");
	console->SetColour(0);
	console->WriteLine();

	cpuid->Go();

	/* NOTES */
	/* The Virtual count is the number of processors that the operating system sees, */
	/* but does not take into account whether any of the processors counted are */
	/* hyperthreads, cores, or truly physical CPUs. */
	/* */
	/* If the Physical and Logical counts are equal, the number of Physical/Logical is the */
	/* core count, because it's a multi-core system. */
	/* */
	/* If a count of the processor packages is needed, simply divide VirtualCount */
	/* by LogicalPerPackage to get the number.  This may fail in some situations where */
	/* the OS or a HyperVisor (VMWare or HyperV) limit the number of processors the OS */
	/* sees - the CPU hardware will still report the total number of cores it has, but */
	/* the underlying software will not have access to it. */

	console->WriteLine("There are %d processors in the system (%d cores per package, %d logical per package).",
	                   cpuid->VirtualCount(),
	                   cpuid->CoresPerPackage(),
	                   cpuid->LogicalPerPackage());

	if (cpuid->VirtualCount() > 1 || cpuid->CoresPerPackage() > 1 || cpuid->LogicalPerPackage() > 1) {
		if (cpuid->CoresPerPackage() == cpuid->LogicalPerPackage())
			console->WriteLine("This is a multi-core system.");
		else if (cpuid->CoresPerPackage() > 1 && cpuid->LogicalPerPackage() > cpuid->CoresPerPackage())
			console->WriteLine("This is a hyperthreaded multi-core system.");
		else if (cpuid->CoresPerPackage() == 1 && cpuid->LogicalPerPackage() > 1)
			console->WriteLine("This is a hyperthreaded system.");

		if (cpuid->VirtualCount() > cpuid->LogicalPerPackage())
			console->WriteLine("This is a multi-processor system.");
	} else {
		console->WriteLine("This is a single processor system.");
	}

	/*
	 * v32 l8 = 32/8 = 4
	 * v4 l2 = 4/2 = 2
	 * v2 l2 = 2/2 = 1
	 * v1 l2 = 1/2 = 0.5
	 */
	double ratio = (double)cpuid->VirtualCount() / (double)cpuid->LogicalPerPackage();
	if ((int)ratio < 1) {
		console->WriteLine();
		console->SetColour(console->FG_YELLOW | console->FG_INTENSITY);
		console->WriteLine("WARNING: Expected at least 1 physical package, but detected %0.2lf. Are you\n"
		                   "running this under a hypervisor?", ratio);
		console->SetColour();
	}

	console->WriteLine();

	for (int i = 0; i < MAX_PROCESSORS; i++) {
		/* Go through each Virtual processor. */
		if (cpuid->proc[i])
			cpuid->proc[i]->Print(console);
	}

	delete cpuid;

#else

	console->WriteLine("CPUID isn't supported on your platform or compiler.");

#endif

	/* End your application here. */

#ifdef TARGET_OS_WINDOWS
	system("pause");
#endif

	delete console;
	return 0;
}