

GitHub - lukechampine/uint128: uint128 for Go
source link: https://github.com/lukechampine/uint128
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

README.md
uint128
go get lukechampine.com/uint128
uint128
provides a high-performance Uint128
type that supports standard arithmetic
operations. Unlike math/big
, operations on Uint128
values always produce new values
instead of modifying a pointer receiver. A Uint128
value is therefore immutable, just
like uint64
and friends.
The name uint128.Uint128
stutters, so I recommend either using a "dot import"
or embedding/aliasing uint128.Uint128
to give it a project-specific name.
Benchmarks
Addition, multiplication, and subtraction are on par with their native 64-bit
equivalents. Division is slower: ~20x slower when dividing a Uint128
by a
uint64
, and ~100x slower when dividing by a Uint128
. However, division is
still faster than with big.Int
(for the same operands), especially when
dividing by a uint64
.
BenchmarkArithmetic/Add-4 2000000000 0.45 ns/op 0 B/op 0 allocs/op
BenchmarkArithmetic/Sub-4 2000000000 0.67 ns/op 0 B/op 0 allocs/op
BenchmarkArithmetic/Mul-4 2000000000 0.42 ns/op 0 B/op 0 allocs/op
BenchmarkArithmetic/Lsh-4 2000000000 1.06 ns/op 0 B/op 0 allocs/op
BenchmarkArithmetic/Rsh-4 2000000000 1.06 ns/op 0 B/op 0 allocs/op
BenchmarkDivision/native_64/64-4 2000000000 0.39 ns/op 0 B/op 0 allocs/op
BenchmarkDivision/Div_128/64-4 2000000000 6.28 ns/op 0 B/op 0 allocs/op
BenchmarkDivision/Div_128/128-4 30000000 45.2 ns/op 0 B/op 0 allocs/op
BenchmarkDivision/big.Int_128/64-4 20000000 98.2 ns/op 8 B/op 1 allocs/op
BenchmarkDivision/big.Int_128/128-4 30000000 53.4 ns/op 48 B/op 1 allocs/op
BenchmarkString/Uint128-4 10000000 173 ns/op 48 B/op 1 allocs/op
BenchmarkString/big.Int-4 5000000 350 ns/op 144 B/op 3 allocs/op
Recommend
-
195
Calcflow A Virtual Reality Tool for Mathematical Modeling! The repository contains the open-sourced code to Calcflow, a powerful mathematical visualization tool designed to give students, educators, and engineers a better grasp on...
-
217
Release 5.0 · javaee/glassfish · GitHub ...
-
465
README.md ViaBTC Exchange Server ViaBTC Exchange Server is a trading backend with high-speed performance, designed for cryptocurrency exchanges. It can...
-
204
Pytorch Exercises Pytorch is one of the most popular deep learning libraries as of 2017. One possible way of familiarizing yourself with it, I think, is to practice with simple quizzes. That's where this project comes in. The outline will...
-
113
Bytom Official golang implementation of the Bytom protocol. Automated builds are available for stable releases and the unstable master branch. Binary archives are published at
-
338
Welcome to tmux! tmux is a terminal multiplexer: it enables a number of terminals to be created, accessed, and controlled from a single screen. tmux may be detached from a screen and continue running in the background, then later reattach...
-
181
-
52
flagg - Barebones subcommand handling
-
380
惊鸿一瞥 这是一个可以帮助你在命令行中完成Github的各种操作的cli工具。 创建它的初衷是因为我是一个命令行狂热爱好者,与此同时我也是一个Github的fans,每当我在命令行环境中进行开发工作时,如果此时我想看看Github上又诞生了什么新的有趣的开源项
-
64
README.md geiger go get lukechampine.com/geiger Inspired by
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK