Update: Python3.11 has some optimizations for % formatting yet it maybe still better to stick with f-strings.
For Python 3.8.6/3.9, I had to do some dirty hacks, because perfplot was giving out some errors. Here assume that x[0] is a a and x[1] is b:

The plot is nearly same for large data. For small data,

Taken by perfplot and this is the code, large data == range(8), small data == range(4).
import perfplot
from random import choice
from string import ascii_lowercase as letters
def generate_random(x):
data = ''.join(choice(letters) for i in range(x))
sata = ''.join(choice(letters) for i in range(x))
return [data,sata]
def fstring_func(x):
return [ord(i) for i in f'{x[0]}{x[1]}']
def format_func(x):
return [ord(i) for i in "{}{}".format(x[0], x[1])]
def replace_func(x):
return [ord(i) for i in "|~".replace('|', x[0]).replace('~', x[1])]
def join_func(x):
return [ord(i) for i in "".join([x[0], x[1]])]
perfplot.show(
setup=lambda n: generate_random(n),
kernels=[
fstring_func,
format_func,
replace_func,
join_func,
],
n_range=[int(k ** 2.5) for k in range(4)],
)
When medium data is there, and four strings are there x[0], x[1], x[2], x[3] instead of two strings:
def generate_random(x):
a = ''.join(choice(letters) for i in range(x))
b = ''.join(choice(letters) for i in range(x))
c = ''.join(choice(letters) for i in range(x))
d = ''.join(choice(letters) for i in range(x))
return [a,b,c,d]

Better to stick with f-strings. Also the speed of %s is similar to .format().