Giter Club home page Giter Club logo

unique's Introduction

unique

Command line filter that only prints unique lines

Similar to uniq but does not require input lines to be sorted.

Example

$ who | unique

unique's People

Contributors

karrick avatar

Stargazers

Rafal W. avatar Doru Carastan avatar

Watchers

James Cloos avatar  avatar

unique's Issues

Slower than awk?

Thanks for the utility, it was very useful.

However when I'm comparing the performance with awk script, it's slower.

Test 1

awk

$ seq 20000000 | time awk '!a[$0]++{print}' | pv -l >/dev/null
22.67user 0.87system 0:23.55elapsed 99%CPU (0avgtext+0avgdata 1616164maxresident)
0inputs+0outputs (0major+403562minor)pagefaults 0swaps
20.0M 0:00:23 [ 849k/s]

unique

$ seq 20000000 | time unique | pv -l >/dev/null
19.68user 10.32system 0:29.74elapsed 100%CPU (0avgtext+0avgdata 860364maxresident)
0inputs+0outputs (0major+224737minor)pagefaults 0swaps
20.0M 0:00:29 [ 672k/s]

Test 2

awk

$ echo | pee "seq 10000000" "seq 10000000" "seq 10000000" | time awk '!a[$0]++{print}' | pv -l | wc -l
14.37user 0.64system 0:15.02elapsed 99%CPU (0avgtext+0avgdata 825032maxresident)
0inputs+0outputs (0major+205782minor)pagefaults 0swaps
10.0M 0:00:15 [ 665k/s]
10000522

unique

$ echo | pee "seq 10000000" "seq 10000000" "seq 10000000" | time unique | pv -l | wc -l
12.67user 5.49system 0:18.02elapsed 100%CPU (0avgtext+0avgdata 431976maxresident)
0inputs+0outputs (0major+115640minor)pagefaults 0swaps
10.0M 0:00:18 [ 554k/s]
10000216

Why the performance is slower than the scripting language?
Are there any methods of improving the performance?
The only plus is that it's using much less memory.

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.