Skip to content

Instantly share code, notes, and snippets.

@KristupasSavickas
Created August 9, 2016 21:36
Show Gist options
  • Select an option

  • Save KristupasSavickas/3b5a267c160846a77382fe92651c5876 to your computer and use it in GitHub Desktop.

Select an option

Save KristupasSavickas/3b5a267c160846a77382fe92651c5876 to your computer and use it in GitHub Desktop.
require 'googl'
require 'open-uri'
require 'google/apis/urlshortener_v1'
ip = open('http://icanhazip.com', &:read).strip
api_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
urls = ["www.facebook.com",
"www.youtube.com",
"www.reddit.com",
"www.imdb.com",
"www.trakt.tv",
"www.music.google.com",
"www.drive.google.com",
"www.mail.google.com",
"www.github.com",
"www.amazon.com",
"www.ebay.com",
"https://github.com/PoVa/sapphire_bot",
"https://github.com/meew0/discordrb",
"https://github.com/meew0/discordrb/blob/master/examples/ping.rb",
"https://github.com/layer8x/youtube-dl.rb",
"https://www.youtube.com/feed/subscriptions",
"https://www.youtube.com/channel/UC2LZO6swZ9SLUEOks3WnsfA",
"https://www.youtube.com/channel/UCUQH21lvN7rpwaatwHGQumg",
"https://www.youtube.com/channel/UCgyqtNWZmIxTx3b6OxTSALw",
"https://www.youtube.com/watch?v=Gp-KzMy0sOc",
"https://www.youtube.com/watch?v=12nwWcY2o3g",
"https://www.youtube.com/watch?v=z5gHGw8sito",
"https://www.youtube.com/watch?v=9v0sxXJr5ic",
"https://www.youtube.com/watch?v=z5gHGw8sito",
"https://www.youtube.com/watch?v=n-9npsIuh4Q",
"https://www.youtube.com/watch?v=aaVA3DwTaEM",
"https://www.youtube.com/watch?v=ObDkWUm10OQ",
"https://www.youtube.com/watch?v=1sgeM6DsV40",
"https://www.youtube.com/watch?v=ZvPxjhTOEgM",
"https://www.youtube.com/watch?v=V2nPsyyme5I",
"https://www.youtube.com/watch?v=ZvPxjhTOEgM",
"https://www.youtube.com/watch?v=BzcvqnazCg4",
"https://www.youtube.com/watch?v=RvWDUi3oEyY",
"https://www.youtube.com/watch?v=UnHN5PfZNtE"
]
googl_avg = 0
official_avg = 0
urls.each do |url|
t = Time.now
shortened_url = Googl.shorten(url, ip, api_key).short_url
time = ((Time.now-t)*1000).to_i
googl_avg += time
puts "Time taken: #{time}ms. Short url: #{shortened_url}, long url: #{url}"
end
shortener = Google::Apis::UrlshortenerV1::UrlshortenerService.new
shortener.key = api_key
urls.each do |url|
t = Time.now
url_object = Google::Apis::UrlshortenerV1::Url.new(long_url: url)
shortened_url = shortener.insert_url(url_object).id
time = ((Time.now-t)*1000).to_i
official_avg += time
puts "Time taken: #{time}ms. Short url: #{shortened_url}, long url: #{url}"
end
puts "Googl average: #{googl_avg / urls.length}. Official api average: #{official_avg / urls.length}"
#=> Googl average: 223. Official api average: 228
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment