<p dir="auto"><code class="notranslate">issubset(x, y)</code> is incredibly slow with vectors of strings compared with the equivalent <code class="notranslate">isempty(setdiff(x, y))</code>. This is because it uses <code class="notranslate">elt in y</code> rather than building a dictionary/set. Of course, <code class="notranslate">issubset</code> can be made even faster than <code class="notranslate">setdiff</code> when the result is <code class="notranslate">false</code> due to the possibility to short-circuit when encountering an element which does not appear in <code class="notranslate">y</code>.</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="julia&gt; x = [@sprintf(&quot;id%010d&quot;, k) for k in 1:9999];

julia&gt; y = [@sprintf(&quot;id%010d&quot;, k) for k in 1:10000];

julia&gt; @time issubset(x, y)
  0.388715 seconds (10.00 k allocations: 156.391 KiB)
true

julia&gt; @time isempty(setdiff(x, y))
  0.004538 seconds (17 allocations: 145.383 KiB)
true"><pre class="notranslate">julia<span class="pl-k">&gt;</span> x <span class="pl-k">=</span> [<span class="pl-c1">@sprintf</span>(<span class="pl-s"><span class="pl-pds">"</span>id%010d<span class="pl-pds">"</span></span>, k) <span class="pl-k">for</span> k <span class="pl-k">in</span> <span class="pl-c1">1</span><span class="pl-k">:</span><span class="pl-c1">9999</span>];

julia<span class="pl-k">&gt;</span> y <span class="pl-k">=</span> [<span class="pl-c1">@sprintf</span>(<span class="pl-s"><span class="pl-pds">"</span>id%010d<span class="pl-pds">"</span></span>, k) <span class="pl-k">for</span> k <span class="pl-k">in</span> <span class="pl-c1">1</span><span class="pl-k">:</span><span class="pl-c1">10000</span>];

julia<span class="pl-k">&gt;</span> <span class="pl-c1">@time</span> <span class="pl-c1">issubset</span>(x, y)
  <span class="pl-c1">0.388715</span> seconds (<span class="pl-c1">10.00</span> k allocations<span class="pl-k">:</span> <span class="pl-c1">156.391</span> KiB)
<span class="pl-c1">true</span>

julia<span class="pl-k">&gt;</span> <span class="pl-c1">@time</span> <span class="pl-c1">isempty</span>(<span class="pl-c1">setdiff</span>(x, y))
  <span class="pl-c1">0.004538</span> seconds (<span class="pl-c1">17</span> allocations<span class="pl-k">:</span> <span class="pl-c1">145.383</span> KiB)
<span class="pl-c1">true</span></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="g = [1:10_000_000;]
m = sample(1:1_000_000, 40_000, replace=false)

@time z = intersect(g,m);
196.291597 seconds (20 allocations: 1.001 MB)"><pre class="notranslate"><code class="notranslate">g = [1:10_000_000;]
m = sample(1:1_000_000, 40_000, replace=false)

@time z = intersect(g,m);
196.291597 seconds (20 allocations: 1.001 MB)
</code></pre></div>
<p dir="auto">Here are two alternate intersections. <del>The latter (isect2) does not preserve</del> neither preserves order.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="function isect(g,m)
    is = []
    for i in m
        if i in g
            push!(is,i)
        end
    end
    return is
end

@time y = isect(g,m);
 12.880327 seconds (40.00 k allocations: 1.611 MB)


function isect2(g,m)
    is = []
    gset = Set(g)
    for i in m
        if i in gset
            push!(is,i)
        end
    end
    return is
end

@time x = isect2(g,m);
  1.430506 seconds (42.75 k allocations: 145.737 MB)

Set(z) == Set(y) == Set(x)
true"><pre class="notranslate"><code class="notranslate">function isect(g,m)
    is = []
    for i in m
        if i in g
            push!(is,i)
        end
    end
    return is
end

@time y = isect(g,m);
 12.880327 seconds (40.00 k allocations: 1.611 MB)


function isect2(g,m)
    is = []
    gset = Set(g)
    for i in m
        if i in gset
            push!(is,i)
        end
    end
    return is
end

@time x = isect2(g,m);
  1.430506 seconds (42.75 k allocations: 145.737 MB)

Set(z) == Set(y) == Set(x)
true
</code></pre></div>