int main(int argc, const char *argv[]) { IOUtils io; io.openStream(argc,argv); std::string input, encrypted, decrypted; input = io.readFromStream(); std::cout << "Original text:" << std::endl << input; // 2. Test various ciphers // Simple ROT13 cipher Rot13Cipher rot13; encrypted = rot13.encrypt(input); std::cout << "Encrypted text:" << std::endl << encrypted; decrypted = rot13.decrypt(encrypted); std::cout << "Decrypted text:" << std::endl << decrypted; if (decrypted == input) std::cout << "Decrypted text matches input!" << std::endl; else { std::cout << "Oops! Decrypted text doesn't match input!" << std::endl; return 1; // Make sure to return a non-zero value to indicate failure } return 0; }
TEST(Test1, pngReadsFromFileMemoryAllocatedByPngReader) { std::cout << "########## Image file read (using high-level PNG API) via inputstream; memory allocated by PngReader" << std::endl; Chrono chrono; IOUtils ioUtuls; ioUtuls.readFile(IMAGE1); MemoryPngInputStream memoryInputstream( (const png_bytep) ioUtuls.getBuffer(), (const png_size_t) ioUtuls.getLength()); std::cout << "Image read info memory in " << chrono.elapsedTimeInMs() << " ms" << std::endl; chrono.reset(); PngReader pngReader1; { pngReader1.readFromInputstream(memoryInputstream); std::cout << "Image read from input stream in " << chrono.elapsedTimeInMs() << " ms" << std::endl; } chrono.reset(); PngReader pngReader2; { memoryInputstream.reset(); pngReader2.readFromInputstream(memoryInputstream, true); std::cout << "Image read from input stream in " << chrono.elapsedTimeInMs() << " ms" << std::endl; } AssertUtil::equals(pngReader1, pngReader2); }
int main(int argc, const char *argv[]) { using namespace std; mr::SentenceStats sentenceStats; std::map<string,int> final; IOUtils io; io.openStream(argc,argv); vector<string> fileNames = io.split(io.readFromStream(),'\n'); io.closeStream(); auto start = std::chrono::steady_clock::now(); // start timer #ifndef PARALLEL_MR // Invoke the Map Reduce runtime mr::run(sentenceStats, fileNames, final); #else // To run the parallel Map Reduce, include -DPARALLEL_MR to // the CXXFLAGS variable in the Makefile, // then make clean and make mr::prun<string,int>(sentenceStats, fileNames, final, 10, 4); #endif auto end = std::chrono::steady_clock::now(); // Print the final results for (auto it = final.begin(); it != final.end(); it++ ) cout << it->first << ": " << it->second << endl; auto diff = end - start; cout << "MapReduce time: " << std::chrono::duration <double, std::milli> (diff).count() << " ms" << endl; return 0; }
int main(int argc, const char *argv[]) { using namespace std; mr::SentenceStats sentenceStats; std::map<string,int> final; IOUtils io; io.openStream(argc,argv); vector<string> fileNames = io.split(io.readFromStream(),'\n'); io.closeStream(); // start timer auto start = std::chrono::steady_clock::now(); #ifndef PARALLEL_MR // Invoke the Map Reduce runtime mr::run(sentenceStats, fileNames, final); #else mr::prun<string,int>(sentenceStats, fileNames, final, 10, 4); #endif auto end = std::chrono::steady_clock::now(); auto diff = end - start; cout << "MapReduce time: " << std::chrono::duration <double, std::milli> (diff).count() << " ms" << endl; return 0; }
int main(int argc, char **argv) { if (argc < 2) { std::cout << "Usage: pgn-app png-in" << std::endl; return 1; } Chrono chrono; chrono.reset(); IOUtils png; png.readFile(argv[1]); MemoryPngInputStream memoryInputstream((const png_bytep) png.getBuffer(), (const png_size_t) png.getLength()); std::cout << "Image read info memory in " << chrono.elapsedTimeInMs() << " ms" << std::endl; { chrono.reset(); PngReader rdrMem; memoryInputstream.reset(); rdrMem.readFromInputstream(memoryInputstream, true); std::cout << "Image read memory (own alloc)in " << chrono.elapsedTimeInMs() << " ms" << std::endl; } chrono.reset(); PngReader rdrMem; memoryInputstream.reset(); rdrMem.readFromInputstream(memoryInputstream); std::cout << "Image read memory (pnglib alloc) in " << chrono.elapsedTimeInMs() << " ms" << std::endl; PngData pngData(rdrMem.getWidth(), rdrMem.getHeight(), rdrMem.getBitDepth(), rdrMem.getColorType(), rdrMem.getPixelDataRowPointers()); std::cout << "Nr of bytes pixelData=" << pngData.getNrOfBytesPixelData() << std::endl; // Loop to see if having a preallocated buffer works better. Answer: yes // Saving was 0-20 ms (on VM on Laptop: (windows7,[email protected] ghz, 8gb) const uint32_t estimatedPngHeaderSize = 1024 * 8; for (int j = 0; j < 10; j++) { for (uint32_t i = 0; i < 2; i++) { uint32_t outputBufferSize = pngData.getNrOfBytesPixelData() + estimatedPngHeaderSize; MemoryPngOutputStream memOs(i * outputBufferSize); chrono.reset(); PngWriter writer(pngData); writer.writePngToOutputStream(memOs); std::cout << "Iteration: " << i << ", image write png to memory in " << chrono.elapsedTimeInMs() << " ms and has size " << memOs.getNrOfBytes() << " bytes" << std::endl; } } return 0; }
// A specialized map function with string keys and int values void SentenceStatus::MRmap(const std::map<std::string,std::string> &input, std::multimap<std::string,int> &out_values) { IOUtils io; // input: in a real Map Reduce application the input will also be a map // where the key is a file name or URL, and the value is the document's contents. // Here we just take the string input and process it. for (auto it = input.begin(); it != input.end(); it++ ) { std::string inputString = io.readFromFile(it->first); std::stringstream ss(inputString); std::string sentence; while(std::getline(ss, sentence, '.')){ out_values.insert(std::pair<std::string,int>(sentence, 1)); } } }
int main(int argc, const char *argv[]) { IOUtils io; io.openStream(argc,argv); std::string input, encrypted, decrypted; input = io.readFromStream(); std::cout << "Original text:" << std::endl << input; CaesarCipher caesar; encrypted = caesar.encrypt(input); std::cout << "Encrypted text:" << std::endl << encrypted; decrypted = caesar.decrypt(encrypted); std::cout << "Decrypted text:" << std::endl << decrypted; if (decrypted == input) std::cout << "Decrypted text matches input!" << std::endl; else { std::cout << "Oops! Decrypted text doesn't match input!" << std::endl; return 1; } return 0; }
TEST(Test1, pngReadsFromMemory) { std::cout << "########## Image memory read" << std::endl; Chrono chrono; IOUtils ioUtuls; ioUtuls.readFile(IMAGE1); MemoryPngInputStream memoryInputstream( (const png_bytep) ioUtuls.getBuffer(), (const png_size_t) ioUtuls.getLength()); std::cout << "Image read info memory in " << chrono.elapsedTimeInMs() << " ms" << std::endl; chrono.reset(); PngReader pngReaderFromMemory; pngReaderFromMemory.readFromInputstream(memoryInputstream); std::cout << "Image read memory in " << chrono.elapsedTimeInMs() << " ms" << std::endl; // Now compare that the data read first in memory produces the same result PngReader pngReaderFromFile; FilePngInputStream filePngInputStream(IMAGE1); pngReaderFromFile.readFromInputstream(filePngInputStream); AssertUtil::equals(pngReaderFromFile, pngReaderFromMemory); }
int main(int argc, const char *argv[]) { using namespace std; // Use MapReduce to compute a word count mr::WordCount wordCount; std::map<string,int> final; // Assume that the URLs to process are listed (one per line) // a file called wordCount-input.txt in the current directory IOUtils io; io.openStream(argc,argv); vector<string> fileNames = io.split(io.readFromStream(),'\n'); io.closeStream(); auto start = std::chrono::steady_clock::now(); // start timer #ifndef PARALLEL_MR // Invoke the Map Reduce runtime mr::run(wordCount, fileNames, final); #else // To run the parallel Map Reduce, include -DPARALLEL_MR to // the CXXFLAGS variable in the Makefile, // then make clean and make mr::prun<string,int>(wordCount, fileNames, final, 10, 4); #endif auto end = std::chrono::steady_clock::now(); // Print the final results for (auto it = final.begin(); it != final.end(); it++ ) cout << it->first << ": " << it->second << endl; auto diff = end - start; cout << "MapReduce time: " << std::chrono::duration <double, std::milli> (diff).count() << " ms" << endl; return 0; }