Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int rleCpu(char *in, int n, char* symbolsOut, int* countsOut) {
- if (n == 0)
- return 0; // nothing to compress!
- int outIndex = 0;
- int symbol = in[0];
- int count = 1;
- for (int i = 1; i < n; ++i) {
- if (in[i] != symbol) {
- // run is over.
- // So output run.
- symbolsOut[outIndex] = symbol;
- countsOut[outIndex] = count;
- outIndex++;
- // and start new run:
- symbol = in[i];
- count = 1;
- }
- else {
- ++count; // run is not over yet.
- }
- }
- // output last run.
- symbolsOut[outIndex] = symbol;
- countsOut[outIndex] = count;
- outIndex++;
- return outIndex;
- }
- //check how long for cpu
- char* symbolsOut;
- int* countsOut;
- std::chrono::time_point<std::chrono::high_resolution_clock> begin, end;
- begin = std::chrono::high_resolution_clock::now();
- symbolsOut = (char*)malloc(N*sizeof(char));
- countsOut = (int*)malloc(N*sizeof(int));
- rleCpu( t, N, symbolsOut, countsOut);
- end = std::chrono::high_resolution_clock::now();
- std::cout << "Time for the CPU:" << std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count() << "ms" << std::endl;
- //
- std::cout <<std::endl << "*************CPU 60 first OUTPUT CHARACTERS*********************";
- std::cout << std::endl;
- for (int j = 0; j < 60; j++)
- std::cout << symbolsOut[j];
- std::cout << std::endl;
- std::cout << "*************CPU 60 first Number of occurances*********************" << std::endl;
- for (int j = 0; j < 60; j++)
- std::cout << countsOut[j];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement