8
\$\begingroup\$

The task is simple, post 2 code snippets that perform the same task, where one seems very optimized at first glance, but actually is significantly slower than the other.

Only one rule:

  • Both snippets must finish with the exact same output (for the same given input, if any).
\$\endgroup\$
3
  • 1
    \$\begingroup\$ Without choosing a specific task, I think this is way too broad to be interesting. You should also specify if both snippets have to use the same language. \$\endgroup\$
    – Dennis
    Commented Jul 6, 2015 at 4:49
  • \$\begingroup\$ @Dennis yeah it might be too broad, I just wanted to see some creative approaches. Also there is no restriction on languages, so that one can get more creative freedom. \$\endgroup\$
    – vrwim
    Commented Jul 6, 2015 at 4:52
  • 9
    \$\begingroup\$ Creative freedom doesn't lead to creative answers. It requires a lot more creativity to solve a difficult task than an easy one. \$\endgroup\$
    – Dennis
    Commented Jul 6, 2015 at 4:57

1 Answer 1

10
\$\begingroup\$

Python 3

Seems fast...

 print(0 < 10**100 - 1 < 10**100)

Seems slow...

 print(10**100 - 1 in range(0, 10**100))

But the two run in very similar times! range has an efficient implementation of in

\$\endgroup\$
2
  • \$\begingroup\$ Question closed aside, isn't this doing the opposite of what the question's asking? You want something that looks fast but is actually slow, not something that looks slow but is actually fast... \$\endgroup\$
    – Sp3000
    Commented Jul 6, 2015 at 11:41
  • 4
    \$\begingroup\$ @Sp3000 right but it was so broad that I decided to post an even broader answer. \$\endgroup\$
    – Caridorc
    Commented Jul 6, 2015 at 11:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.