GithubHelp home page GithubHelp logo

algorithm_sorting_part1's Introduction

2016Algorithm_01

Simple sorting problem

##Init version

Analysis result:

result
I_refs 111363392
check 1.000000/1.000000
cpu_time 30.162ms
flt 1364
gcc 0
heap_lost 0
illegal_func 0
illegal_header 0
m_error 0
m_peak 59457536
maxrss 2170880
@lang=cpp

##Insertion sort version

Analysis result:

result
I_refs 5091383206
check 1.000000/1.000000
cpu_time 64.9071ms
flt 1113
gcc 0
heap_lost 0
illegal_func 0
illegal_header 0
m_error 0
m_peak 58482688
maxrss 1454080
@lang=cpp

##Final version

Analysis result:

result
I_refs 94385289
check 1.000000/1.000000
cpu_time 24.234ms
flt 1108
gcc 0
heap_lost 0
illegal_func 0
illegal_header 0
m_error 0
m_peak 58478592
maxrss 1437696
@lang=cpp

(All with the same input, from small data to mass data)

#Conclusion

For the sorting algorithm, I used std::sort to test it. And I also test it with insertion sort which spent years to run it(O( n^2 )) and it's number of instructions consumed are too big, so I won't talk about it.

The first version's maximun resident size (maxrss) had much more bigger than Final version.

I did it just by discarding the stringstream and using a char to do the input. Although it seems clumsy, it does reduce the maxrss and also the CPU time.

So, if there are a great amount of data to be inputed, it is better to avoid using stingstream. Because stringstream use too mush memory to do the buffer things.

But there are still pros of using it, such as reading a line of seperated ints or strings until '\n'. And it can simply be done by getline() and split it by ss<<str; => ss>>(int or str);.

And the cons of using char and reading it digit by digit is that it is really indigenous, and it can cause many bugs.

This is just my rough conclusion.

algorithm_sorting_part1's People

Contributors

ashhwu avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.