<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>KousakuinX</author_name>
  <author_url>https://blog.hatena.ne.jp/KousakuinX/</author_url>
  <blog_title>地上の洞窟</blog_title>
  <blog_url>https://under-overworld.hatenablog.jp/</blog_url>
  <categories>
    <anon>Ruby</anon>
  </categories>
  <description>※古いRuby(1.9)のお話、新しいバージョンではマイナス乗とか気にしなくていい！目次 前置き 改善 結論 余談 前置き n = 10 2 ** n 2のn乗。オーソドックスな書き方だ。 しかしRubyにおいて2のn乗を普通に書くのは 速度的にはあんましえらくない。とされている*1 1 &lt;&lt; n このように「ビットシフト」を用いて、「2のn乗」を高速化できる。 require &quot;benchmark&quot; n = 32 Benchmark.bm(4) do |r| r.report(&quot;**&quot;) { 10_000_000.times { 2 ** n } } r.report(&quot;&lt;&lt;&quot;) { 10_…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Funder-overworld.hatenablog.jp%2Fentry%2F2023%2F08%2F18%2F200104&quot; title=&quot;Rubyで「マイナス乗」を計算しようとしてびびった話。 - 地上の洞窟&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url></image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2023-08-18 20:01:04</published>
  <title>Rubyで「マイナス乗」を計算しようとしてびびった話。</title>
  <type>rich</type>
  <url>https://under-overworld.hatenablog.jp/entry/2023/08/18/200104</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
