-
-
Save ppknap/e4e9e68c46268555b5fb13d3e16b2f63 to your computer and use it in GitHub Desktop.
This file contains 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 main | |
import ( | |
"archive/zip" | |
"bytes" | |
"compress/flate" | |
"compress/gzip" | |
"encoding/base64" | |
"encoding/json" | |
"fmt" | |
"io" | |
"log" | |
"time" | |
"koding/klient/machine/index" | |
humanize "github.com/dustin/go-humanize" | |
) | |
func main() { | |
now := time.Now() | |
idx, err := index.NewIndexFiles("/home/pawelknap/koding/koding/") | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println("Scanning time: ", time.Since(now)) | |
now = time.Now() | |
b, err := json.Marshal(idx) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println("JSON: ", humanize.IBytes(uint64(len(b)))) | |
fmt.Println("JSON time: ", time.Since(now)) | |
now = time.Now() | |
buf := new(bytes.Buffer) | |
// Create a new zip archive. | |
w := zip.NewWriter(buf) | |
w.RegisterCompressor(zip.Deflate, func(out io.Writer) (io.WriteCloser, error) { | |
return flate.NewWriter(out, flate.BestCompression) | |
}) | |
f, err := w.Create("index.remote") | |
if err != nil { | |
log.Fatal(err) | |
} | |
_, err = f.Write(b) | |
if err != nil { | |
log.Fatal(err) | |
} | |
err = w.Close() | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Println("ZIP: ", humanize.IBytes(uint64(buf.Len()))) | |
fmt.Println("ZIP time: ", time.Since(now)) | |
now = time.Now() | |
var bgzip bytes.Buffer | |
wgzip := gzip.NewWriter(&bgzip) | |
wgzip.Write(b) | |
wgzip.Close() | |
fmt.Println("GZIP: ", humanize.IBytes(uint64(bgzip.Len()))) | |
fmt.Println("GZIP time: ", time.Since(now)) | |
now = time.Now() | |
sEnc := base64.StdEncoding.EncodeToString(bgzip.Bytes()) | |
fmt.Println("GZIP BASE64: ", humanize.IBytes(uint64(len(sEnc)))) | |
fmt.Println("GZIP BASE64 time: ", time.Since(now)) | |
now = time.Now() | |
count := idx.Count(-1) | |
fmt.Println("Count: ", count) | |
fmt.Println("Count time: ", time.Since(now)) | |
now = time.Now() | |
ds := idx.DiskSize(-1) | |
fmt.Println("DiskSize: ", humanize.IBytes(uint64(ds))) | |
fmt.Println("DiskSize time: ", time.Since(now)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment