There is no significant difference in memory efficiency. Since strings are immutable, both approaches must copy the entire data.
To check performance, you can use the timeit
module in standard libraries. Slicing is significantly faster, due to avoiding iteration within Python code:
>>> s = "google"
>>> %timeit "".join(reversed(s))
612 ns ± 20.8 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
>>> %timeit s[::-1]
157 ns ± 3.96 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
And the runtime improvement is increasing for larger strings:
>>> s = s*1000
>>> %timeit "".join(reversed(s))
119 µs ± 2.37 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)
>>> %timeit s[::-1]
10.8 µs ± 123 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
CPython 3.7.0b4 on macOS.