Skip to content

Commit

Permalink
trying simdjson 3.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
FourierTransformer committed Oct 4, 2023
1 parent f824840 commit 6cb53cd
Show file tree
Hide file tree
Showing 6 changed files with 124,802 additions and 17,173 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SRC = src/luasimdjson.cpp src/simdjson.cpp
INCLUDE = -I$(LUA_INCDIR)
LIBS_PATH = -L$(LUA_LIBDIR)
LIBS = -lpthread
FLAGS = -std=c++11 -Wall $(LIBFLAG) $(CFLAGS)
FLAGS = -std=c++11 -Wall -O3 $(LIBFLAG) $(CFLAGS)

all: simdjson.so

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

A basic lua binding to [simdjson](https://simdjson.org). The simdjson library is an incredibly fast JSON parser that uses SIMD instructions and fancy algorithms to parse JSON very quickly. It's been tested with LuaJIT 2.0/2.1 and Lua 5.1, 5.2, 5.3, and 5.4 on linux/osx. It has a general parsing mode and a lazy mode that uses a JSON pointer.

Current simdjson version: 0.5.0
Current simdjson version: 3.3.0

## Installation
If all the requirements are met, lua-simdjson can be install via luarocks with:
Expand Down Expand Up @@ -82,7 +82,7 @@ local response = simdjson.open([[
print(response:atPointer("/Image/Width"))

-- OR to parse a file from disk
local fileResponse = simdjson.open("jsonexamples/twitter.json")
local fileResponse = simdjson.openFile("jsonexamples/twitter.json")
print(fileResponse:atPointer("/statuses/0/id")) --using a JSON pointer

```
Expand Down
37 changes: 35 additions & 2 deletions spec/compile_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,44 @@ local files = {
"small/truenull.json"
}

describe("Make sure everything compiled correctly", function()
describe("Make sure it parses strings correctly", function()
for _, file in ipairs(files) do
it("should parse the file: " .. file, function()
local fileContents = loadFile("jsonexamples/" .. file)
assert.are.same(cjson.decode(fileContents), simdjson.parse(fileContents))
local cjsonDecodedValues = cjson.decode(fileContents)
assert.are.same(cjsonDecodedValues, simdjson.parse(fileContents))
end)
end
end)

describe("Make sure it parses files correctly", function()
for _, file in ipairs(files) do
it("should parse the file: " .. file, function()
local fileContents = loadFile("jsonexamples/" .. file)
local cjsonDecodedValues = cjson.decode(fileContents)
assert.are.same(cjsonDecodedValues, simdjson.parseFile("jsonexamples/" .. file))
end)
end
end)

describe("Make sure json pointer works with a string", function()
it("should handle a string", function()
local fileContents = loadFile("jsonexamples/small/demo.json")
local decodedFile = simdjson.open(fileContents)
assert.are.same(800, decodedFile:atPointer("/Image/Width"))
assert.are.same(600, decodedFile:atPointer("/Image/Height"))
assert.are.same(125, decodedFile:atPointer("/Image/Thumbnail/Height"))
assert.are.same(943, decodedFile:atPointer("/Image/IDs/1"))
end)
end)

describe("Make sure json pointer works with openfile", function()
it("should handle opening a file", function()
local decodedFile = simdjson.openFile("jsonexamples/small/demo.json")
assert.are.same(800, decodedFile:atPointer("/Image/Width"))
assert.are.same(600, decodedFile:atPointer("/Image/Height"))
assert.are.same(125, decodedFile:atPointer("/Image/Thumbnail/Height"))
assert.are.same(943, decodedFile:atPointer("/Image/IDs/1"))
end)
end)

7 changes: 4 additions & 3 deletions src/luasimdjson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,10 @@ static int parse_file(lua_State *L)

static int active_implementation(lua_State *L)
{
std::string name = simdjson::active_implementation->name();
std::string description = simdjson::active_implementation->description();
std::string implementation_name = name + " (" + description + ")";
const auto& implementation = simdjson::get_active_implementation();
const std::string name = implementation->name();
const std::string description = implementation->description();
const std::string implementation_name = name + " (" + description + ")";

lua_pushlstring(L, implementation_name.data(), implementation_name.size());

Expand Down
Loading

0 comments on commit 6cb53cd

Please sign in to comment.