Skip to content

Commit

Permalink
Improve benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
njaremko committed Dec 25, 2024
1 parent 7bef97e commit 8b2d378
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
6 changes: 1 addition & 5 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@ RbSys::ExtensionTask.new("osv", GEMSPEC) do |ext|
ext.ext_dir = "ext/osv"
end

task :dev do
ENV["RB_SYS_CARGO_PROFILE"] = "dev"
end

Rake::TestTask.new do |t|
t.deps << :dev << :compile
t.deps << :compile
t.test_files = FileList[File.expand_path("test/*_test.rb", __dir__)]
t.libs << "lib"
t.libs << "test"
Expand Down
2 changes: 2 additions & 0 deletions benchmark/run_benchmarks.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail

export RB_SYS_CARGO_PROFILE=release

echo "🧹 Cleaning previous build..."
cargo clean

Expand Down
20 changes: 20 additions & 0 deletions test/basic_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,26 @@ def test_parse_csv_with_empty_field
end
end

def test_parse_csv_with_empty_field_as_nil_string
Tempfile.create(%w[test .csv]) do |tempfile|
# Copy existing content and add a line with empty field
content = File.read("test/test.csv")
content += "4,,40\n"
tempfile.write(content)
tempfile.close

expected = [
{ "id" => "1", "age" => "25", "name" => "John" },
{ "name" => "Jane", "id" => "2", "age" => "30" },
{ "name" => "Jim", "age" => "35", "id" => "3" },
{ "id" => "4", "name" => nil, "age" => "40" }
]
actual = []
OSV.for_each(tempfile.path, nil_string: "") { |row| actual << row }
assert_equal expected, actual
end
end

def test_parse_csv_with_missing_field_default_strict
Tempfile.create(%w[test .csv]) do |tempfile|
content = File.read("test/test.csv")
Expand Down

0 comments on commit 8b2d378

Please sign in to comment.