char* MenuSupport::MakePalindrom(const char* const source) { char* result = new char[maxStringLenght]; StringCopy(result, source); if (!IsPalindrom(source)) { int sourceLenght = StringLength(source); int iteretionNumber = 0; for (iteretionNumber = 0; iteretionNumber < sourceLenght; iteretionNumber++) { char* tempStringBegin = new char[maxStringLenght]; char* tempStringEnd = new char[maxStringLenght]; int index = 0; for (index = 0; index < iteretionNumber + 1; index++) { tempStringBegin[index] = source[index]; } tempStringBegin[index] = '\0'; StringCopy(tempStringEnd, &source[iteretionNumber + 1]); if (IsPalindrom(tempStringBegin) && StringLength(tempStringBegin) > 1) { char* newEnd = new char[maxStringLenght]; StringCopy(newEnd, tempStringEnd); StringRevers(tempStringEnd); StringCopy(result, tempStringEnd); int resultLenght = StringLength(result); for (int i = 0; tempStringBegin[i]; i++) { result[resultLenght] = tempStringBegin[i]; resultLenght++; } result[resultLenght] = '\0'; StringConcatenation(result, newEnd); delete[] newEnd; delete[] tempStringBegin; delete[] tempStringEnd; break; } else if (IsPalindrom(tempStringEnd)) { StringRevers(tempStringBegin); StringConcatenation(result, tempStringBegin); delete[] tempStringBegin; delete[] tempStringEnd; break; } else delete[] tempStringBegin; delete[] tempStringEnd; continue; } } return result; }
void MenuSupport::runMenu() { bool canExit = false; while (!canExit) { printMenuAndTakeChoise(); if (_userChoise == 0) continue; switch (_userChoise) { case kReturStringLenghtChoiseType: { printf(kEnterAimStringMessage); printf(kInputSymbolMessage); char* ptrAimStringLenght = new char[maxStringLenght]; gets_s(ptrAimStringLenght, maxStringLenght); int stringLenght = StringLength(ptrAimStringLenght); printf(kLenghtOfAimStringMessage, stringLenght); delete[] ptrAimStringLenght; _userChoise = 0; break; } case kCopyOneStringToAnotheChoiseType: { printf(kEnterDestinationStringMessage); printf(kInputSymbolMessage); char* ptrDestinationStringCopy = new char[maxStringLenght]; gets_s(ptrDestinationStringCopy, maxStringLenght); printf(kEnterSourceStringMessage); printf(kInputSymbolMessage); char* ptrSourceStringCopy = new char[maxStringLenght]; gets_s(ptrSourceStringCopy, maxStringLenght); StringCopy(ptrDestinationStringCopy, ptrSourceStringCopy); printf(kDestinationStringAfterCPInfoMessage, ptrDestinationStringCopy); delete[] ptrDestinationStringCopy; delete[] ptrSourceStringCopy; _userChoise = 0; break; } case kStringConcatanationChoiseType: { printf(kEnterDestinationStringConcatenationMessage); printf(kInputSymbolMessage); char* ptrDestinationStringConcatenation = new char[maxStringLenght]; gets_s(ptrDestinationStringConcatenation, maxStringLenght); printf(kEnterSourceStringConcatenationMessage); printf(kInputSymbolMessage); char* ptrSourceStringConcatenation = new char[maxStringLenght]; gets_s(ptrSourceStringConcatenation, maxStringLenght); StringConcatenation(ptrDestinationStringConcatenation, ptrSourceStringConcatenation); printf(kDestinationStringAfterConcatInfoMessage, ptrDestinationStringConcatenation); delete[] ptrDestinationStringConcatenation; delete[] ptrSourceStringConcatenation; _userChoise = 0; break; } case kSubstringIndexFindeChoiseType: { printf(kEnterSourceStringForSearchingMessage); printf(kInputSymbolMessage); char* ptrSourceStringForSearching = new char[maxStringLenght]; gets_s(ptrSourceStringForSearching, maxStringLenght); printf(kEnterSearchingSubstringMessage); printf(kInputSymbolMessage); char* ptrSearchingSubstring = new char[maxStringLenght]; gets_s(ptrSearchingSubstring, maxStringLenght); int index = IndexOfSubstring(ptrSourceStringForSearching, ptrSearchingSubstring); printf(kIndexResultInfoMessage, index+1); delete[] ptrSourceStringForSearching; delete[] ptrSearchingSubstring; _userChoise = 0; break; } case kFindOutPolindromChoiseType: { printf(kEnterStringForPolindromCheckMessage); printf(kInputSymbolMessage); char* ptrStringPolindromCheck = new char[maxStringLenght]; gets_s(ptrStringPolindromCheck, maxStringLenght); printf(kPolindromCheckMessage); if (IsPalindrom(ptrStringPolindromCheck)) { printf(kConfirmMessage); } else { printf(kDenialMessage); } delete[] ptrStringPolindromCheck; _userChoise = 0; break; } case kMakePolindromChoiseType: { printf(kEnterStringForPolindromMakeMessage); printf(kInputSymbolMessage); char* ptrStringPolindromMake = new char[maxStringLenght]; gets_s(ptrStringPolindromMake, maxStringLenght); char* ptrPolindrom = MakePalindrom(ptrStringPolindromMake); printf(kResultPolindromMessage, ptrPolindrom); delete[] ptrPolindrom; delete[] ptrStringPolindromMake; _userChoise = 0; break; } case kCleanScreanChoiseType: { system("cls"); _userChoise = 0; break; } case kExitProgramChoiseType: { printf(kExitConfirmationMessage); printf(kInputSymbolMessage); char answerString[20]; gets_s(answerString); int lenght = strlen(answerString); for (int i = 0; i < lenght; i++) answerString[i] = tolower(answerString[i]); if (strcmp(answerString, "y") == 0 || strcmp(answerString, "yes") == 0) canExit = true; break; } default: { printf(kEnterCorrectValueMessage); break; } } } }
void cMiniBench::RunTests() { if( TestsToRun[ eAes ] ) { StatusBarUpdate( "Running AES ECB Encypt/Decrypt Tests..." ); cAesBench AesBench; StatusBarUpdate( "Running AES 8kB ECB Encypt/Decrypt Tests..." ); OutputRaw( AesBench.runEncryptBenchmark8KB( true ), "AES ECB Encrypt 8kB score: " ); OutputRaw( AesBench.runDecryptBenchmark8KB( true ), "AES ECB Decrypt 8kB score: " ); StatusBarUpdate( "Running AES 16kB ECB Encypt/Decrypt Tests..." ); OutputRaw( AesBench.runEncryptBenchmark16KB( true ), "AES ECB Encrypt 16kB score: " ); OutputRaw( AesBench.runDecryptBenchmark16KB( true ), "AES ECB Decrypt 16kB score: " ); StatusBarUpdate( "Running AES 32kB ECB Encypt/Decrypt Tests..." ); OutputRaw( AesBench.runEncryptBenchmark32KB( true ), "AES ECB Encrypt 32kB score: " ); OutputRaw( AesBench.runDecryptBenchmark32KB( true ), "AES ECB Decrypt 32kB score: " ); StatusBarUpdate( "Running AES 64kB ECB Encypt/Decrypt Tests..." ); OutputRaw( AesBench.runEncryptBenchmark64KB( true ), "AES ECB Encrypt 64kB score: " ); OutputRaw( AesBench.runDecryptBenchmark64KB( true ), "AES ECB Decrypt 64kB score: " ); StatusBarUpdate( "Running AES 128kB ECB Encypt/Decrypt Tests..." ); OutputRaw( AesBench.runEncryptBenchmark128KB( true ), "AES ECB Encrypt 128kB score: " ); OutputRaw( AesBench.runDecryptBenchmark128KB( true ), "AES ECB Decrypt 128kB score: " ); StatusBarUpdate( "Running AES 256kB ECB Encypt/Decrypt Tests..." ); OutputRaw( AesBench.runEncryptBenchmark256KB( true ), "AES ECB Encrypt 256kB score: " ); OutputRaw( AesBench.runDecryptBenchmark256KB( true ), "AES ECB Decrypt 256kB score: " ); StatusBarUpdate( "Running AES 512kB ECB Encypt/Decrypt Tests..." ); OutputRaw( AesBench.runEncryptBenchmark512KB( true ), "AES ECB Encrypt 512kB score: " ); OutputRaw( AesBench.runDecryptBenchmark512KB( true ), "AES ECB Decrypt 512kB score: " ); StatusBarUpdate( "Running AES 1024kB ECB Encypt/Decrypt Tests..." ); OutputRaw( AesBench.runEncryptBenchmark1024KB( true ), "AES ECB Encrypt 1024kB score: " ); OutputRaw( AesBench.runDecryptBenchmark1024KB( true ), "AES ECB Decrypt 1024kB score: " ); StatusBarUpdate( "Running AES 2048kB ECB Encypt/Decrypt Tests..." ); OutputRaw( AesBench.runEncryptBenchmark2048KB( true ), "AES ECB Encrypt 2048kB score: " ); OutputRaw( AesBench.runDecryptBenchmark2048KB( true ), "AES ECB Decrypt 2048kB score: " ); StatusBarUpdate( "Running AES 4096kB ECB Encypt/Decrypt Tests..." ); OutputRaw( AesBench.runEncryptBenchmark4096KB( true ), "AES ECB Encrypt 4096kB score: " ); OutputRaw( AesBench.runDecryptBenchmark4096KB( true ), "AES ECB Decrypt 4096kB score: " ); StatusBarUpdate( "Running AES 8192kB ECB Encypt/Decrypt Tests..." ); OutputRaw( AesBench.runEncryptBenchmark8192KB( true ), "AES ECB Encrypt 8192kB score: " ); OutputRaw( AesBench.runDecryptBenchmark8192KB( true ), "AES ECB Decrypt 8192kB score: " ); StatusBarUpdate( "Running AES 16384kB ECB Encypt/Decrypt Tests..." ); OutputRaw( AesBench.runEncryptBenchmark16384KB( true ), "AES ECB Encrypt 16384kB score: " ); OutputRaw( AesBench.runDecryptBenchmark16384KB( true ), "AES ECB Decrypt 16384kB score: " ); } if( TestsToRun[ eDhrystone ] ) { StatusBarUpdate( "Running Dhrystone..." ); CDhryApp dhry( 20000000 ); OutputSeconds( dhry.RunTest( 20000000 ), "Dhrystone" ); } if( TestsToRun[ eDoubleArithmetic ] ) { StatusBarUpdate( "Running Double Arithmetic..." ); OutputSeconds( doubleArithmetic( 10000000000.0, 11000000000.0 ), "Double Arithmetic (s): " ); } if( TestsToRun[ eFibonacci ] ) { StatusBarUpdate( "Running Fibonacci( 42 )..." ); cFibTest FibTest( 1 ); OutputSeconds( FibTest.Run(), "Fib(42)" ); } if( TestsToRun[ eFft ] ) { StatusBarUpdate( "Running FFT..." ); cFFT FFT( 1 ); OutputSeconds( FFT.Run(), "FFT" ); } if( TestsToRun[ eFlops ] ) { cFlops lFlops; // addition: StatusBarUpdate( "MFLOPS SP Add..." ); OutputRaw( lFlops.runFpuFloatAddTest(), "MFLOPS (SP add): " ); StatusBarUpdate( "MFLOPS DP Add..." ); OutputRaw( lFlops.runFpuDoubleAddTest(), "MFLOPS (DP add): " ); // multiplication StatusBarUpdate( "MFLOPS SP Mul..." ); OutputRaw( lFlops.runFpuFloatMulTest(), "MFLOPS (SP mul): " ); StatusBarUpdate( "MFLOPS DP Mul..." ); OutputRaw( lFlops.runFpuDoubleMulTest(), "MFLOPS (DP mul): " ); // division: StatusBarUpdate( "MFLOPS SP Div..." ); OutputRaw( lFlops.runFpuFloatDivTest(), "MFLOPS (SP div): " ); StatusBarUpdate( "MFLOPS DP Div..." ); OutputRaw( lFlops.runFpuDoubleDivTest(), "MFLOPS (DP div): " ); // mul-add: StatusBarUpdate( "MFLOPS DP Mul-Add..." ); OutputRaw( lFlops.runFpuDoubleMulAdd3Test(), "MFLOPS (DP mul-add): " ); } if( TestsToRun[ eHeapSort ] ) { StatusBarUpdate( "Running Heap Sort..." ); OutputSeconds( HeapSortTest( 5000000 ), "Heap Sort (s): " ); } if( TestsToRun[ eIntArithmetic ] ) { StatusBarUpdate( "Running Integer Arithmetic..." ); OutputSeconds( intArithmetic( 1000000000 ), "Integer Arithmetic (s): " ); } if( TestsToRun[ eInt64Arithmetic ] ) { StatusBarUpdate( "Running 64-bit Arithmetic..." ); OutputSeconds( longArithmetic( 10000000000LL, 11000000000LL ), "64-bit Arithmetic (s): " ); } if( TestsToRun[ eIntegerMatrixMul ] ) { StatusBarUpdate( "Running Integer Matrix Multiplication..." ); OutputSeconds( IntegerMatrixMultiplication( 1 ), "Integer Matrix Multiplication (s): " ); } if( TestsToRun[ eIO ] ) { StatusBarUpdate( "Running I/O..." ); OutputSeconds( io( 10000000 ), "I/O (s): " ); remove( "DeleteMe_minibench.txt" ); } if( TestsToRun[ eLinpack ] ) { cLinpackTest lLinpack( 1 ); StatusBarUpdate( "Running Linpack rolled..." ); lLinpack.Run(); OutputRaw( lLinpack.GetFlops(), "LinPack rolled (FLOPS): " ); StatusBarUpdate( "Running Linpack unrolled..." ); lLinpack.SetRolling( eUnrolled ); lLinpack.Run(); OutputRaw( lLinpack.GetFlops(), "LinPack unrolled (FLOPS): " ); } if( TestsToRun[ eAllMemoryTests] ) { StatusBarUpdate( "Memory Bandwidth Integer Write (MB/s): " ); OutputRaw( BandwidthIntegerWrite( 2000000 ), "Memory Bandwidth Integer Write (MB/s): " ); StatusBarUpdate( "Memory Bandwidth MemCpy (MB/s): " ); OutputRaw( BandwidthMemCpy( 2000000 ), "Memory Bandwidth MemCpy (MB/s): " ); StatusBarUpdate( "Memory Bandwidth Double Copy (MB/s): " ); OutputRaw( BandwidthDoubleCopy( 2000000 ), "Memory Bandwidth Double Copy (MB/s): " ); } if( TestsToRun[ eRandomAssignment ] ) { StatusBarUpdate( "Memory Latency Random Assignment (MB/s): " ); OutputRaw( RandomAssignment( 2000000 ), "Memory Latency Random Assignment (MB/s): " ); } if( TestsToRun[ ePi ] ) { StatusBarUpdate( "Running Pi( 10,000 )..." ); int i = 0; { i += PiTest( 10000 ); } OutputSeconds( i, "Pi to 10,000 digits (s): " ); } if( TestsToRun[ eQueens ] ) { StatusBarUpdate( "Running Queens..." ); double ldRunTime = 0; cQueensTest Queens( 1 ); ldRunTime = Queens.Run(); /* #pragma omp parallel { num_threads = omp_get_num_threads(); CQueens Queens; #pragma omp atomic ldRunTime += Queens.RunTest(25000); } */ cout << "Queens (seconds per thread): " << ldRunTime << endl; cout << "Number of threads = " << Queens.GetNumberOfThreads() << endl; } if( TestsToRun[ eSha1 ] ) { StatusBarUpdate( "Running SHA1 Tests..." ); cSha1Bench lSha1Bench; if( lSha1Bench.runSha1ValidationTests( true ) ) { OutputSeconds( lSha1Bench.runBenchmark( true ), "SHA1 (s): " ); // OutputRaw( lSha1Bench.getScoreOverall() ); // OutputRaw( lSha1Bench.getScoreForSmallStrings(), "SHA1 small strings: " ); // Sha1Score50KString = lSha1Bench.getScoreFor50kString(); // Sha1Score1MString = lSha1Bench.getScoreFor1MString(); // Sha1Score10MString = lSha1Bench.getScoreFor10MString(); // } // if } else { cerr << "Sha1 validation tests failed!" << endl; StatusBarUpdate( "Sha1 validation tests failed!" ); } // if...else } if( TestsToRun[ eSha256 ] ) { cSha256Bench lSha256Bench; if( lSha256Bench.runSha256ValidationTests( true ) ) { StatusBarUpdate( "Executing SHA-256 timed tests..." ); OutputSeconds( lSha256Bench.runBenchmark( true ), "SHA256 (s): " ); // cerr << "The benchmark took " << TestTime << " milliseconds for all hash tests." << endl; // if( Sha256ScoreOverall < lSha256Bench.getScoreOverall() ) // { // Sha256ScoreOverall = lSha256Bench.getScoreOverall(); // Sha256ScoreSmallStrings = lSha256Bench.getScoreForSmallStrings(); // Sha256Score50KString = lSha256Bench.getScoreFor50kString(); // Sha256Score1MString = lSha256Bench.getScoreFor1MString(); // Sha256Score10MString = lSha256Bench.getScoreFor10MString(); // } // if } else { StatusBarUpdate( "Sha256 validation tests failed!" ); } // if...else } if( TestsToRun[ eSieve ] ) { StatusBarUpdate( "Sieve..." ); OutputSeconds( Sieve( 50000 ), "Sieve (s): " ); } if( TestsToRun[ eStringConcat ] ) { StatusBarUpdate( "String Concatenation..." ); OutputSeconds( StringConcatenation( 40000000 ), "String Concatenation (s): " ); } if( TestsToRun[ eTrig ] ) { StatusBarUpdate( "Running Trig..." ); OutputSeconds( trig( 10000000 ), "Trig (s): " ); } if( TestsToRun[ eWhetstone ] ) { StatusBarUpdate( "Running Whetstone..." ); CWhetApp whet; OutputSeconds( whet.RunTest( 50000 ), "Whetstone (s): " ); } StatusBarUpdate( "All tests finished!" ); }