CARVIEW |
Select Language
HTTP/2 200
date: Wed, 30 Jul 2025 21:56:32 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
etag: W/"267bb1e78e87c8af2928dfca449138e2"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: origin-when-cross-origin, strict-origin-when-cross-origin
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com wss://alive-staging.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=CabArYI3IdQVkLt5TY0A0b%2BEIotJYrfp6%2BYGD272IEJy%2FME0Oa9qO%2FvjSLbfcNsoukeJM4SRy2HAlVO7qNoYvxqshSbklykx7v8o2hKOti0qkvSrljchr487uhItscXlFUEGuFNCI0zNq9U%2F9ZMPKHGa4wboFQmwg%2BeFBtiHCkf7HBrF6KPy7VL6Gg0SuanxXFaRGj0Cah4HP%2B8rxAff8vePFlN%2FaQFe0kr1hY6kbV7CWnPCyV%2BfXLw8rkDYa%2FfH3u9k57Jb%2F8fNa9YtFFETEw%3D%3D--S31TEvSP%2FalOP%2F3g--3EYW6tm99KKDfdmGiljq%2FQ%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.249425782.1753912591; Path=/; Domain=github.com; Expires=Thu, 30 Jul 2026 21:56:31 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Thu, 30 Jul 2026 21:56:31 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: 943A:FA5FC:6810B:9740B:688A950F
csvlib_benchmark · GitHub
Show Gist options
Save tiendc/c394677a846233bf8de819da3bb7093c to your computer and use it in GitHub Desktop.
{{ message }}
Instantly share code, notes, and snippets.
Created
July 4, 2023 10:58
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save tiendc/c394677a846233bf8de819da3bb7093c to your computer and use it in GitHub Desktop.
csvlib_benchmark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package benchmark | |
import ( | |
"bytes" | |
"encoding/csv" | |
"testing" | |
"github.com/gocarina/gocsv" | |
"github.com/jszwec/csvutil" | |
"github.com/tiendc/go-csvlib" | |
"github.com/yunabe/easycsv" | |
) | |
// NOTE: This benchmark code is copied from the bench test of the project https://github.com/jszwec/csvutil | |
// Unmarshal bench: https://gist.github.com/jszwec/e8515e741190454fa3494bcd3e1f100f | |
// Marshal bench: https://gist.github.com/jszwec/31980321e1852ebb5615a44ccf374f17 | |
func BenchmarkUnmarshal(b *testing.B) { | |
type A struct { | |
A int `csv:"a" name:"a"` | |
B float64 `csv:"b" name:"b"` | |
C string `csv:"c" name:"c"` | |
D int64 `csv:"d" name:"d"` | |
E int8 `csv:"e" name:"e"` | |
F float32 `csv:"f" name:"f"` | |
G float32 `csv:"g" name:"g"` | |
H float32 `csv:"h" name:"h"` | |
I string `csv:"i" name:"i"` | |
J int `csv:"j" name:"j"` | |
} | |
fixture := []struct { | |
desc string | |
records int | |
}{ | |
{ | |
desc: "100 records", | |
records: 100, | |
}, | |
{ | |
desc: "1000 records", | |
records: 1000, | |
}, | |
{ | |
desc: "10000 records", | |
records: 10000, | |
}, | |
{ | |
desc: "100000 records", | |
records: 100000, | |
}, | |
} | |
tests := []struct { | |
desc string | |
fn func([]byte, *testing.B) | |
}{ | |
{ | |
desc: "csvlib.Unmarshal", | |
fn: func(data []byte, b *testing.B) { | |
var a []A | |
if _, err := csvlib.Unmarshal(data, &a); err != nil { | |
b.Error(err) | |
} | |
}, | |
}, | |
{ | |
desc: "csvutil.Unmarshal", | |
fn: func(data []byte, b *testing.B) { | |
var a []A | |
if err := csvutil.Unmarshal(data, &a); err != nil { | |
b.Error(err) | |
} | |
}, | |
}, | |
{ | |
desc: "gocsv.Unmarshal", | |
fn: func(data []byte, b *testing.B) { | |
var a []A | |
if err := gocsv.UnmarshalBytes(data, &a); err != nil { | |
b.Error(err) | |
} | |
}, | |
}, | |
{ | |
desc: "easycsv.ReadAll", | |
fn: func(data []byte, b *testing.B) { | |
r := easycsv.NewReader(bytes.NewReader(data)) | |
var a []A | |
if err := r.ReadAll(&a); err != nil { | |
b.Error(err) | |
} | |
}, | |
}, | |
} | |
for _, t := range tests { | |
b.Run(t.desc, func(b *testing.B) { | |
for _, f := range fixture { | |
b.Run(f.desc, func(b *testing.B) { | |
data := genData(f.records) | |
for i := 0; i < b.N; i++ { | |
t.fn(data, b) | |
} | |
}) | |
} | |
}) | |
} | |
} | |
func genData(records int) []byte { | |
header := []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"} | |
record := []string{"1", "2.5", "foo", "6", "7", "8", "9", "10", "bar", "10"} | |
var buf bytes.Buffer | |
w := csv.NewWriter(&buf) | |
w.Write(header) | |
for i := 0; i < records; i++ { | |
w.Write(record) | |
} | |
w.Flush() | |
if err := w.Error(); err != nil { | |
panic(err) | |
} | |
return buf.Bytes() | |
} | |
func BenchmarkMarshal(b *testing.B) { | |
type A struct { | |
A int `csv:"a"` | |
B float64 `csv:"b"` | |
C string `csv:"c"` | |
D int64 `csv:"d"` | |
E int8 `csv:"e"` | |
F float32 `csv:"f"` | |
G float32 `csv:"g"` | |
H float32 `csv:"h"` | |
I string `csv:"i"` | |
J int `csv:"j"` | |
} | |
fixture := []struct { | |
desc string | |
records int | |
}{ | |
{ | |
desc: "100 records", | |
records: 100, | |
}, | |
{ | |
desc: "1000 records", | |
records: 1000, | |
}, | |
{ | |
desc: "10000 records", | |
records: 10000, | |
}, | |
{ | |
desc: "100000 records", | |
records: 100000, | |
}, | |
} | |
tests := []struct { | |
desc string | |
fn func([]A, *testing.B) | |
}{ | |
{ | |
desc: "csvlib.Marshal", | |
fn: func(as []A, b *testing.B) { | |
if _, err := csvlib.Marshal(as); err != nil { | |
b.Error(err) | |
} | |
}, | |
}, | |
{ | |
desc: "csvutil.Marshal", | |
fn: func(as []A, b *testing.B) { | |
if _, err := csvutil.Marshal(as); err != nil { | |
b.Error(err) | |
} | |
}, | |
}, | |
{ | |
desc: "gocsv.Marshal", | |
fn: func(as []A, b *testing.B) { | |
var buf bytes.Buffer | |
if err := gocsv.Marshal(as, &buf); err != nil { | |
b.Error(err) | |
} | |
}, | |
}, | |
} | |
a := A{ | |
A: 1, | |
B: 3.14, | |
C: "string", | |
D: 1, | |
E: 1, | |
F: 3.13, | |
G: 3.14, | |
H: 3.14, | |
I: "string", | |
J: 10, | |
} | |
for _, t := range tests { | |
b.Run(t.desc, func(b *testing.B) { | |
for _, f := range fixture { | |
b.Run(f.desc, func(b *testing.B) { | |
as := make([]A, f.records) | |
for i := range as { | |
as[i] = a | |
} | |
for i := 0; i < b.N; i++ { | |
t.fn(as, b) | |
} | |
}) | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can’t perform that action at this time.