Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ukrbublik/nif_sorter
Faster sort typed list of strings/integers/floats for Elixir
https://github.com/ukrbublik/nif_sorter
elixir nif sort
Last synced: about 1 month ago
JSON representation
Faster sort typed list of strings/integers/floats for Elixir
- Host: GitHub
- URL: https://github.com/ukrbublik/nif_sorter
- Owner: ukrbublik
- Created: 2019-07-20T22:02:07.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-07-24T14:26:10.000Z (over 5 years ago)
- Last Synced: 2024-05-02T01:38:48.027Z (7 months ago)
- Topics: elixir, nif, sort
- Language: Elixir
- Homepage: https://hex.pm/packages/nif_sorter
- Size: 21.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# nif_sorter
[![CircleCI](https://circleci.com/gh/ukrbublik/nif_sorter.svg?style=svg)](https://circleci.com/gh/ukrbublik/nif_sorter)NIF faster sort typed list of strings/integers/floats (with C++ `std::sort`)
### Installation
Add to `deps` in `mix.exs`:
```elixir
{:nif_sorter, "~> 0.2.2"}
```
Works on Elixir 1.7+### Usage
```elixir
NifSorter.sort(["xir", "i", "el"])
# ["el", "i", "xir"]
NifSorter.sort([2, 3, 1])
# [1, 2, 3]
NifSorter.sort([2.31, 2.07, 1.2, -10.4])
# [-10.4, 1.2, 2.07, 2.31]NifSorter.sort([1, 2.2])
# (ArgumentError) argument error
```### Restrictions
- Works only on strictly typed lists.
Supported types: `string`, `integer`, `float`.
Can't mix types in list like `NifSorter.sort(["aa", 12, 1.33])`
- Sort by integers works for integers in range `-9223372036854775808 .. 9223372036854775807`### Performance
- See benchmarks for
- [integers](bench_results/int.md)
- [floats](bench_results/float.md)
- [strings](bench_results/str.md)
- Memory usage is more efficient.
- Sort list of numbers is 2-3x faster.
- Sort list of strings wins by speed on big data (~30% faster on 100K).### Commands
- Interactive shell:
```sh
$ make cli
```
- Run benchmarks:
```sh
$ make bench
$ make bench/fast
```
- Run tests:
```sh
$ make test
```