Giter Site home page Giter Site logo

karolsluszniak / process-csv Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 1.0 7 KB

Simple Elixir vs Ruby project for checking performance of both languages when it comes to processing large text files (as part of command line script or background job process).

Home Page: http://cloudless.pl/articles/12-elixir-vs-ruby-file-i-o-performance

Elixir 84.40% Ruby 15.60%

process-csv's Introduction

This is a source code for the article Elixir vs Ruby: File I/O performance that you can find on the Phoenix on Rails blog. It's basically a sample text file processing script implemented in Elixir and Ruby that does the following:

  1. Loads the input CSV, line by line.
  2. Parses first column which is of format Some text N.
  3. Leaves only those lines where N is dividable by 2 or 5.
  4. Saves those filtered, but unchanged lines into another CSV.

It does so both in a streaming manner, which is slower but works with all file sizes, and as a faster but less secure and less universal one-shot read.

Disclaimer: I'm not after proving that either Elixir or Ruby is "better" at reading files. This is just an exercise to better understand the practical consequences of running simple command-line script via MRI vs running it in a complex Erlang VM environment.

Generating samples

You can generate sample CSV file of given size, compilant with the algorithm, like this:

ruby lib/generate.rb sample-500k.csv 500000

The syntax is: ruby lib/generate.rb <filename> <rows> [<cols>] where <cols> default to 3.

Running benchmarks

Elixir version:

MIX_ENV=prod mix escript.build
time ./process_csv sample-500k.csv [read | stream]

Ruby version:

time ruby lib/process_csv.rb sample-500k.csv [read | stream]

Improvements

Please look into the article to see which optimizations I've tried. Open Pull Request if you've found a better way.

process-csv's People

Contributors

karolsluszniak avatar

Stargazers

Justin Smestad avatar 0x00evil avatar

Watchers

James Cloos avatar  avatar

Forkers

theflowglenn

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.