Instantly share code, notes, and snippets.
Save miyataka/8787021724ee7dc5cecea88913f3af8c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# frozen_string_literal: true | |
require'benchmark/ips' | |
require'fcm' | |
require'andpush' | |
require'fcmpush' | |
require'google/apis/messages' | |
require'firebase_cloud_messenger' | |
server_key=ENV.fetch('FCM_SERVER_KEY') | |
DEVICE_TOKEN=ENV.fetch('TEST_DEVICE_TOKEN') | |
project_id=ENV.fetch('TEST_PROJECT_ID') | |
FCM_CLIENT=FCM.new(server_key) | |
PAYLOAD_FOR_FCM={notification:{title:'u',body:'y'}}.freeze | |
REGISTRATION_TOKENS=[DEVICE_TOKEN].freeze | |
ANDPUSH_CLIENT=Andpush.build(server_key) | |
PAYLOAD_FOR_ANDPUSH=PAYLOAD_FOR_FCM.merge(to:DEVICE_TOKEN) | |
FCMPUSH_CLIENT=Fcmpush.build(project_id) | |
PAYLOAD_FOR_FCMPUSH={message:{token:DEVICE_TOKEN,notification:{title:'u',body:'y'}}}.freeze | |
# GOOGLEAPIFCM_CLIENT = Google::Apis::Messages::MessagesService.new(project_id: project_id) | |
# GOOGLEAPIFCM_CLIENT.authorization = Google::Auth.get_application_default(Google::Apis::Messages::AUTH_MESSAGES) | |
# PAYLOAD_FOR_GOOGLEAPIFCM = Google::Apis::Messages::Message.new(token: DEVICE_TOKEN, title: 'u', body: 'y').freeze | |
FirebaseCloudMessenger.project_id=project_id | |
PAYLOAD_FOR_FIREBASECLOUDMESSENGER={token:DEVICE_TOKEN,notification:{title:'u',body:'y'}}.freeze | |
Benchmark.ipsdo |x| | |
# using legacy HTTP API | |
x.report('andpush'){ANDPUSH_CLIENT.push(PAYLOAD_FOR_ANDPUSH).json} | |
x.report('fcm'){FCM_CLIENT.send(REGISTRATION_TOKENS,PAYLOAD_FOR_FCM)} | |
# using V1 HTTP API | |
x.report('fcmpush'){FCMPUSH_CLIENT.push(PAYLOAD_FOR_FCMPUSH).json} | |
# x.report('google-api-fcm') { GOOGLEAPIFCM_CLIENT.notify(PAYLOAD_FOR_GOOGLEAPIFCM) } | |
x.report('firebase_cloud_messenger'){FirebaseCloudMessenger.send(message:PAYLOAD_FOR_FIREBASECLOUDMESSENGER)} | |
x.compare! | |
end |
This file contains hidden or 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
source'https://rubygems.org' | |
gem'benchmark-ips' | |
gem'fcm' | |
gem'andpush' | |
gem'fcmpush' | |
gem'google-api-fcm' | |
gem'firebase_cloud_messenger' |
This file contains hidden or 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
GEM | |
remote:https://rubygems.org/ | |
specs: | |
activesupport (6.1.3) | |
concurrent-ruby (~>1.0,>=1.0.2) | |
i18n (>=1.6,<2) | |
minitest (>=5.1) | |
tzinfo (~>2.0) | |
zeitwerk (~>2.3) | |
addressable (2.7.0) | |
public_suffix (>=2.0.2,<5.0) | |
andpush (0.2.1) | |
net-http-persistent (>=3.0.0) | |
benchmark-ips (2.8.4) | |
concurrent-ruby (1.1.8) | |
connection_pool (2.2.3) | |
declarative (0.0.20) | |
declarative-option (0.1.0) | |
faraday (1.0.1) | |
multipart-post (>=1.2,<3) | |
fcm (1.0.2) | |
faraday (~>1.0.0) | |
fcmpush (1.3.1) | |
google-apis-identitytoolkit_v3 | |
net-http-persistent (~>4.0.1) | |
firebase_cloud_messenger (0.4.1) | |
googleauth (~>0.6) | |
json-schema (~>2.8) | |
gems (1.2.0) | |
google-api-client (0.53.0) | |
google-apis-core (~>0.1) | |
google-apis-generator (~>0.1) | |
google-api-fcm (0.1.8) | |
google-api-client (~>0.17) | |
google-apis-core (0.3.0) | |
addressable (~>2.5,>=2.5.1) | |
googleauth (~>0.14) | |
httpclient (>=2.8.1,<3.0) | |
mini_mime (~>1.0) | |
representable (~>3.0) | |
retriable (>=2.0,<4.0) | |
rexml | |
signet (~>0.14) | |
webrick | |
google-apis-discovery_v1 (0.2.0) | |
google-apis-core (~>0.1) | |
google-apis-generator (0.2.0) | |
activesupport (>=5.0) | |
gems (~>1.2) | |
google-apis-core (~>0.1) | |
google-apis-discovery_v1 (~>0.0) | |
thor (>=0.20,<2.a) | |
google-apis-identitytoolkit_v3 (0.2.0) | |
google-apis-core (~>0.1) | |
googleauth (0.16.0) | |
faraday (>=0.17.3,<2.0) | |
jwt (>=1.4,<3.0) | |
memoist (~>0.16) | |
multi_json (~>1.11) | |
os (>=0.9,<2.0) | |
signet (~>0.14) | |
httpclient (2.8.3) | |
i18n (1.8.9) | |
concurrent-ruby (~>1.0) | |
json-schema (2.8.1) | |
addressable (>=2.4) | |
jwt (2.2.2) | |
memoist (0.16.2) | |
mini_mime (1.0.2) | |
minitest (5.14.4) | |
multi_json (1.15.0) | |
multipart-post (2.1.1) | |
net-http-persistent (4.0.1) | |
connection_pool (~>2.2) | |
os (1.1.1) | |
public_suffix (4.0.6) | |
representable (3.0.4) | |
declarative (<0.1.0) | |
declarative-option (<0.2.0) | |
uber (<0.2.0) | |
retriable (3.1.2) | |
rexml (3.2.4) | |
signet (0.15.0) | |
addressable (~>2.3) | |
faraday (>=0.17.3,<2.0) | |
jwt (>=1.5,<3.0) | |
multi_json (~>1.10) | |
thor (1.1.0) | |
tzinfo (2.0.4) | |
concurrent-ruby (~>1.0) | |
uber (0.1.0) | |
webrick (1.7.0) | |
zeitwerk (2.4.2) | |
PLATFORMS | |
x86_64-darwin-20 | |
DEPENDENCIES | |
andpush | |
benchmark-ips | |
fcm | |
fcmpush | |
firebase_cloud_messenger | |
google-api-fcm | |
BUNDLED WITH | |
2.2.3 |
This file contains hidden or 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
Warming up -------------------------------------- | |
andpush 1.000 i/100ms | |
fcm 1.000 i/100ms | |
fcmpush 1.000 i/100ms | |
firebase_cloud_messenger | |
1.000 i/100ms | |
Calculating ------------------------------------- | |
andpush 19.236 (±10.4%) i/s - 95.000 in 5.048723s | |
fcm 6.536 (±15.3%) i/s - 33.000 in 5.083179s | |
fcmpush 18.871 (±10.6%) i/s - 93.000 in 5.031072s | |
firebase_cloud_messenger | |
3.238 (± 0.0%) i/s - 17.000 in 5.265755s | |
Comparison: | |
andpush: 19.2 i/s | |
fcmpush: 18.9 i/s - same-ish: difference falls within error | |
fcm: 6.5 i/s - 2.94x (± 0.00) slower | |
firebase_cloud_messenger: 3.2 i/s - 5.94x (± 0.00) slower |
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment