-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve constant pool resolving speed (#16)
* Add a simple parsing test * Do not resolve same instances multiple times * rm unused example.jfr (not gzipped) file
- Loading branch information
1 parent
6ac8ddf
commit 3228ecf
Showing
8 changed files
with
84 additions
and
9 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.idea/ |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package parser | ||
|
||
import ( | ||
"bytes" | ||
"compress/gzip" | ||
"encoding/json" | ||
"io/ioutil" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestParse(t *testing.T) { | ||
jfr, err := readGzipFile("./testdata/example.jfr.gz") | ||
if err != nil { | ||
t.Fatalf("Unable to read JFR file: %s", err) | ||
} | ||
expectedJson, err := readGzipFile("./testdata/example_parsed.json.gz") | ||
if err != nil { | ||
t.Fatalf("Unable to read example_parsd.json") | ||
} | ||
chunks, err := Parse(bytes.NewReader(jfr)) | ||
if err != nil { | ||
t.Fatalf("Failed to parse JFR: %s", err) | ||
return | ||
} | ||
actualJson, _ := json.Marshal(chunks) | ||
if !bytes.Equal(expectedJson, actualJson) { | ||
t.Fatalf("Failed to parse JFR: %s", err) | ||
return | ||
} | ||
} | ||
|
||
func BenchmarkParse(b *testing.B) { | ||
jfr, err := readGzipFile("./testdata/example.jfr.gz") | ||
if err != nil { | ||
b.Fatalf("Unable to read JFR file: %s", err) | ||
} | ||
for i := 0; i < b.N; i++ { | ||
_, err := Parse(bytes.NewReader(jfr)) | ||
if err != nil { | ||
b.Fatalf("Unable to parse JFR file: %s", err) | ||
} | ||
} | ||
} | ||
|
||
func readGzipFile(fname string) ([]byte, error) { | ||
f, err := os.Open(fname) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer f.Close() | ||
r, err := gzip.NewReader(f) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer r.Close() | ||
return ioutil.ReadAll(r) | ||
} |
Binary file not shown.
Binary file not shown.
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