All Projects → quasilyte → concat

quasilyte / concat

Licence: MIT license
Demo repository for habr.com article about faster Go string concatenation.

Programming Languages

go
31211 projects - #10 most used programming language
assembly
5116 projects

Projects that are alternatives of or similar to concat

Algorithm-Implementation
This is our effort to collect the best implementations to tough algorithms. All codes are written in c++.
Stars: ✭ 16 (+0%)
Mutual labels:  strings
poeditor-cli
POEditor CLI
Stars: ✭ 29 (+81.25%)
Mutual labels:  strings
ostrich
An SMT Solver for string constraints
Stars: ✭ 18 (+12.5%)
Mutual labels:  strings
envs
Easy access of environment variables from Python with support for typing (ex. booleans, strings, lists, tuples, integers, floats, and dicts). Now with CLI settings file converter.
Stars: ✭ 25 (+56.25%)
Mutual labels:  strings
solidity-standard-library
Solidity standard library (Array, random, math, string)
Stars: ✭ 61 (+281.25%)
Mutual labels:  strings
android-localization-helper
A python script that helps you create strings.xml for all languages in different hierarchical folder(using Google Translation API)
Stars: ✭ 19 (+18.75%)
Mutual labels:  strings
algoexpert
AlgoExpert is an online platform that helps software engineers to prepare for coding and technical interviews.
Stars: ✭ 8 (-50%)
Mutual labels:  strings
Libft
42 library of basic C functions - queues, lists, memory operations and more 😄
Stars: ✭ 21 (+31.25%)
Mutual labels:  strings
strings-ansi
Handle ANSI escape codes in strings
Stars: ✭ 17 (+6.25%)
Mutual labels:  strings
bigint
bigint is a C++ library which can handle Very very Big Integers. It can calculate factorial of 1000000... it can go any big. It may be useful in Competitive Coding and Scientific Calculations which deals with very very large Integers. It can also be used in Decryption process. It has many inbuilt functions which can be very useful.
Stars: ✭ 34 (+112.5%)
Mutual labels:  strings
bootstrap-4-boilerplate
Basic Bootstrap 4 Starter Template
Stars: ✭ 50 (+212.5%)
Mutual labels:  concatenation
python-string-utils
A handy Python library to validate, manipulate and generate strings
Stars: ✭ 47 (+193.75%)
Mutual labels:  strings
regXwild
⏱ Superfast ^Advanced wildcards++? | Unique algorithms that was implemented on native unmanaged C++ but easily accessible in .NET via Conari (with caching of 0x29 opcodes +optimizations) etc.
Stars: ✭ 20 (+25%)
Mutual labels:  strings
s3-concat
Concat multiple files in s3
Stars: ✭ 35 (+118.75%)
Mutual labels:  concatenation
strings-case
Convert strings between different cases.
Stars: ✭ 65 (+306.25%)
Mutual labels:  strings
slice
A JavaScript implementation of Python's negative indexing and extended slice syntax.
Stars: ✭ 53 (+231.25%)
Mutual labels:  strings
s3-concat
Concatenate Amazon S3 files remotely using flexible patterns
Stars: ✭ 32 (+100%)
Mutual labels:  concatenation
simplehstore
🏪 Easy way to use a PostgreSQL database (and the HSTORE feature) from Go
Stars: ✭ 54 (+237.5%)
Mutual labels:  strings
concat
🐱 concatenate files
Stars: ✭ 38 (+137.5%)
Mutual labels:  concat
common
Metarhia Common Library
Stars: ✭ 55 (+243.75%)
Mutual labels:  strings

Concat

Demo package for Ускорение конкатенации строк в Go своими руками article.

Overview

This package provides simple functions that return concatenation results. Can work faster than Go + operator.

You should not use this package, really. It's just an example.

Benchmarks

BenchmarkConcat2Operator/short-8         	20000000	        84.4 ns/op
BenchmarkConcat2Operator/longer-8        	10000000	       158 ns/op
BenchmarkConcat2Builder/short-8          	20000000	        70.7 ns/op
BenchmarkConcat2Builder/longer-8         	10000000	       127 ns/op
BenchmarkConcat2/short-8                 	30000000	        57.3 ns/op
BenchmarkConcat2/longer-8                	20000000	       106 ns/op
BenchmarkConcat3Operator/short-8         	20000000	       103 ns/op
BenchmarkConcat3Operator/longer-8        	10000000	       217 ns/op
BenchmarkConcat3Builder/short-8          	20000000	        89.9 ns/op
BenchmarkConcat3Builder/longer-8         	 5000000	       249 ns/op
BenchmarkConcat3/short-8                 	20000000	        85.0 ns/op
BenchmarkConcat3/longer-8                	10000000	       189 ns/op

Number one is unsafe concatenation, second is strings.Builder with preallocated buffer and "obvious" concatenation is the slowest one... unless CL123256 is applied.

Using the benchstat, here is the difference between concat and +:

name              old time/op  new time/op  delta
Concat2/short-8   84.4ns ± 2%  64.3ns ± 4%  -23.85%  (p=0.000 n=14+15)
Concat2/longer-8   138ns ± 1%   118ns ± 1%  -14.83%  (p=0.000 n=13+15)
Concat3/short-8    105ns ± 5%    82ns ± 5%  -22.29%  (p=0.000 n=15+14)
Concat3/longer-8   218ns ± 1%   192ns ± 1%  -11.95%  (p=0.000 n=15+15)

If compared with AMD64 asm version for concat2:

name              old time/op  new time/op  delta
Concat2/short-8   84.4ns ± 0%  56.9ns ± 5%  -32.54%  (p=0.000 n=15+15)
Concat2/longer-8   138ns ± 1%   107ns ± 0%  -22.51%  (p=0.000 n=13+15)

As a bonus, asm version also makes empty strings concatenation optimization, just like runtime version of concat would.

Example

package main

import (
	"fmt"

	"github.com/Quasilyte/concat"
)

func main() {
	v := "world!"
	fmt.Println(concat.Strings("hello, ", v)) // => "hello, world!"
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].