Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add bm_adapter #1914

Merged
merged 1 commit into from
Sep 13, 2016
Merged

Conversation

NullVoxPopuli
Copy link
Contributor

@NullVoxPopuli NullVoxPopuli commented Sep 6, 2016

Purpose

Compores the different adapters

Changes

added bm_adapter.rb

$ bin/bench
attributes 1124.3438848105818/ips; 1784 objects
json_api 261.8025877761349/ips; 3873 objects
json 1071.236972223799/ips; 1839 objects
Benchmark results:
{
  "commit_hash": "1dc2b74",
  "version": "0.10.2",
  "rails_version": "4.2.4",
  "benchmark_run[environment]": "2.3.1p112",
  "runs": [
    {
      "benchmark_type[category]": "attributes",
      "benchmark_run[result][iterations_per_second]": 1124.344,
      "benchmark_run[result][total_allocated_objects_per_iteration]": 1784
    },
    {
      "benchmark_type[category]": "json_api",
      "benchmark_run[result][iterations_per_second]": 261.803,
      "benchmark_run[result][total_allocated_objects_per_iteration]": 3873
    },
    {
      "benchmark_type[category]": "json",
      "benchmark_run[result][iterations_per_second]": 1071.237,
      "benchmark_run[result][total_allocated_objects_per_iteration]": 1839
    }
  ]
}

System:
image

ruby -v

ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]

The other benchmarks for reference:

camel 354.91746231137375/ips; 3653 objects
camel_lower 431.25456403665754/ips; 2622 objects
dash 2792.965163577614/ips; 770 objects
unaltered 7149615.074971388/ips; 1 objects
underscore 5023.107909424926/ips; 313 objects
Benchmark results:
{
  "commit_hash": "1dc2b74",
  "version": "0.10.2",
  "rails_version": "4.2.4",
  "benchmark_run[environment]": "2.3.1p112",
  "runs": [
    {
      "benchmark_type[category]": "camel",
      "benchmark_run[result][iterations_per_second]": 354.917,
      "benchmark_run[result][total_allocated_objects_per_iteration]": 3653
    },
    {
      "benchmark_type[category]": "camel_lower",
      "benchmark_run[result][iterations_per_second]": 431.255,
      "benchmark_run[result][total_allocated_objects_per_iteration]": 2622
    },
    {
      "benchmark_type[category]": "dash",
      "benchmark_run[result][iterations_per_second]": 2792.965,
      "benchmark_run[result][total_allocated_objects_per_iteration]": 770
    },
    {
      "benchmark_type[category]": "unaltered",
      "benchmark_run[result][iterations_per_second]": 7149615.075,
      "benchmark_run[result][total_allocated_objects_per_iteration]": 1
    },
    {
      "benchmark_type[category]": "underscore",
      "benchmark_run[result][iterations_per_second]": 5023.108,
      "benchmark_run[result][total_allocated_objects_per_iteration]": 313
    }
  ]
}

caching on: caching serializers: gc off 992.4002533974954/ips; 1270 objects
caching on: fragment caching serializers: gc off 969.5608152595304/ips; 1367 objects
caching on: non-caching serializers: gc off 1103.4800266979528/ips; 1219 objects
caching off: caching serializers: gc off 1031.1505750964488/ips; 1270 objects
caching off: fragment caching serializers: gc off 974.1763206821167/ips; 1367 objects
caching off: non-caching serializers: gc off 1107.8862969827758/ips; 1219 objects
Benchmark results:
{
  "commit_hash": "1dc2b74",
  "version": "0.10.2",
  "rails_version": "4.2.4",
  "benchmark_run[environment]": "2.3.1p112",
  "runs": [
    {
      "benchmark_type[category]": "caching on: caching serializers: gc off",
      "benchmark_run[result][iterations_per_second]": 992.4,
      "benchmark_run[result][total_allocated_objects_per_iteration]": 1270
    },
    {
      "benchmark_type[category]": "caching on: fragment caching serializers: gc off",
      "benchmark_run[result][iterations_per_second]": 969.561,
      "benchmark_run[result][total_allocated_objects_per_iteration]": 1367
    },
    {
      "benchmark_type[category]": "caching on: non-caching serializers: gc off",
      "benchmark_run[result][iterations_per_second]": 1103.48,
      "benchmark_run[result][total_allocated_objects_per_iteration]": 1219
    },
    {
      "benchmark_type[category]": "caching off: caching serializers: gc off",
      "benchmark_run[result][iterations_per_second]": 1031.151,
      "benchmark_run[result][total_allocated_objects_per_iteration]": 1270
    },
    {
      "benchmark_type[category]": "caching off: fragment caching serializers: gc off",
      "benchmark_run[result][iterations_per_second]": 974.176,
      "benchmark_run[result][total_allocated_objects_per_iteration]": 1367
    },
    {
      "benchmark_type[category]": "caching off: non-caching serializers: gc off",
      "benchmark_run[result][iterations_per_second]": 1107.886,
      "benchmark_run[result][total_allocated_objects_per_iteration]": 1219
    }
  ]
}

@richmolj
Copy link
Contributor

richmolj commented Sep 6, 2016

Looks great to me 👍 But probably someone else should merge this one since I'm still learning what should be in and out of scope for this library.

One things come to mind, independent of merging. Some of these results might be misleading in the 'real world'. For instance with json-api pagination links, an extra database query would be fired in a real-word ActiveRecord/Rails app, slowing things down, but nothing would be fired with a PORO.

@NullVoxPopuli
Copy link
Contributor Author

Yeah, I'd like to write another benchmark which does the same as above, but against active record. :-)

@richmolj
Copy link
Contributor

@NullVoxPopuli I am now thinking we should just merge unless there are concerns. I find myself using this a lot, actually, when just poking around the code.

@NullVoxPopuli NullVoxPopuli merged commit 810efb8 into rails-api:master Sep 13, 2016
@NullVoxPopuli NullVoxPopuli deleted the add-adapter-benchmark branch September 13, 2016 15:20
richmolj pushed a commit to richmolj/active_model_serializers that referenced this pull request Sep 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants