Swap encoding iteration count Introduction
In this challenge, I asked you to implement swap encoding.
Swap encoding is an encoding method where you iterate through the string, reversing substrings between identical characters. The basic algorithm is:
For each character in the string:
Check: Does the string contain the character again, after the instance you found?
If so, then modify the string by reversing the section between the character and the next instance, inclusive.
Otherwise do nothing.
Example
Start with the string 'eat potatoes'.
e is found again, so reverse that section: eotatop taes
o is found again, so reverse that section (doing nothing as it is palindromic)
t is found again, so reverse that section (doing nothing as it is palindromic)
a is found again, so reverse that section: eotat potaes
t is found again, so reverse that section: eotatop taes
None of 'op taes' are found again, so eotatop taes is our final string!
Anyway, in this chat, @okie and I discussed what would happen if you repeatedly ran the swap algorithm on something until it returned to the original string. We managed to prove that it will always return.
Okay, that's a lot of preamble. Here's your challenge:
Write a program or function that takes a string as input, and returns the number of times it has to be swapped before it will return to itself.
Scoring
Answers will be timed on their combined score on all the scored testcases, so please append a snippet to your program that runs all the testcases one after another.
I will time all answers on all on my computer (2018 Macbook Air), although please link to a downloadable interpreter/compiler for less mainstream languages.
Here is my reference implementation.
Testcases
Simple testcases (Just to check it works):
1231 =&gt; 2
1234512345 =&gt; 6
123142523
Sandbox for Proposed Challenges =&gt; 1090
Collatz, Sort, Repeat =&gt; 51
Rob the King: Hexagonal Mazes =&gt; 144
Decompress a Sparse Matrix =&gt; 8610
14126453467324231 =&gt; 1412
12435114151241 - 288
Closest Binary Fraction =&gt; 242
Quote a rational number =&gt; 282
Solve the Alien Probe puzzle =&gt; 5598

Scored testcases (The ones I'm timing you on)
124351141512412435325 =&gt; 244129
Write a fast-growing assembly function =&gt; 1395376
And I'm now heading to the elevator =&gt; 207478
I'm in the now infamous elevator =&gt; 348112
1549827632458914598012734 =&gt; 1025264
i was always mediocre at golfing =&gt; 1232480
tho, i like some code challenges =&gt; 2759404
I am once again in an elevator =&gt; 1606256
A person with mannerism of cat =&gt; 867594

IMPORTANT
To make it fair, I have to time all programs under the same load on my computer. So if one person requests a retime, I have to retime them all. This means your time may fluctate.
C++ (gcc), 3.809 seconds

Compile with g++ -O3 -std=c++14.
As requested by the OP, the testcases were included in the source.
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include &lt;stdlib.h&gt;

constexpr int TESTCASES_NUM = 9;
constexpr char *TESTCASES[TESTCASES_NUM] = {"124351141512412435325", "Write a fast-growing assembly function", "And I'm now heading to the elevator", "I'm in the now infamous elevator", "1549827632458914598012734", "i was always mediocre at golfing", "tho, i like some code challenges", "I am once again in an elevator", "A person with mannerism of cat"};

int solve(char *s, int n) {
    int ans = 0;
    int i, j;
    char *p, *q, b;
    char s0[n];
    memcpy(s0, s, n);
    do {
        for(i = 0; i &lt; n; ++i) {
            for(j = i + 1; j &lt; n; ++j) {
                if(s[i] == s[j]) {
                    for(p = s + i + 1, q = s + j - 1; p &lt; q; ++p, --q) {
                        b = *p;
                        *p = *q;
                        *q = b;
                    }
                    break;
                }
            }
        }
        ++ans;
    } while (memcmp(s0, s, n));
    return ans;
}

int main(int argc, char **argv) {
    for(int t = 0; t &lt; TESTCASES_NUM; ++t) {
        char* s = TESTCASES[t];
        int  n = strlen(s);
       &#32;
        int count[300];
        memset(count, 0, sizeof(count));
        for(int i = 0; i &lt; n; ++i) {
            ++count[s[i]];
        }
        char z[n];
        int m = 0;
        for(int i = 0; i &lt; n; ++i) {
            if(count[s[i]] == 1) {
                if(i &gt; 1 and count[s[i - 1]] == 1 and count[s[i - 2]] == 1) {
                    continue;
                }
            }
            if(i &gt; 1 and s[i] == s[i - 2] and count[s[i - 1]] == 1) {
                --m;
                continue;
            }
            if(m == 0 and count[s[i]] == 0) {
                continue;
            }
            z[m++] = s[i];
        }
        while(m &gt; 1 and count[z[m - 1]] == 1) {
            --m;
        }
       &#32;
        printf("%d\n", solve(z, m));
    }
}

Try it online!
The naive implementation, with a couple of preprocessing optimizations.
Say that a character is unique if it occurs exactly once in the input string.

If there are more than 2 consecutive unique characters, we can remove some of them until there are exactly 2 consecutive ones.
We can remove every prefix or suffix consisting entirely of unique characters.
We can make substitutions aba -&gt; a whenever b is unique (thanks to kops for the suggestion!).