If the original code is working, go back to the original code. The original code is solid code; just stop calling it over and over again.
You should be running this in a game loop that draws one frame buffer per loop.
I haven't used Assimp yet, but I have written a program that takes animation data for the standard Humanoid Armature in Blender and plays it back as a stick figure. And my program allowed you to select which animation you wanted to play back from the file. So, I'm sure Assimp is doing basically the same thing.
But you don't want this code to run every frame. You want this function to be called when it's time to move to a new animation. That's probably once, and then again when you want to play a different animation, not every frame. This is the "change the animation" code, not the "play the animation" code. Depending on how many animations the file contained, this could be a fairly expensive look-up. Just the fact that it is string based makes it a bit of an ugly lookup. But calling animations by name is easier than by number. All you are trying to do here is to get a pointer to the correct animation by supplying the animation's name; you need that once - not in a loop. So, use something to trigger this call when needed.
If there is only one animation in the file, you may not even need a loop here and can just pick the first one.
But I would probably stick with this. If you call this in your Update() for your game loop when a button is pressed or when some other event occurs signaling a different animation than you'll only run this code once in a blue moon. My program had a switch statement so that if you pressed the right arrow it selected the next animation and if you hit the left arrow it went to the previous animation.
But the code is returning a pointer to an animation. This is just allowing you to select which animation you want since an animation file can contain an infinite number of animations in one file. Usually the animator names the animations and so selecting them by name is pretty natural. Or at least that's what I assume by looking at the code. I imagine what Assimp is calling a channel is a single animation. Then each channel/animation contains a series of key frames. Then you have to provide the animation between the key frames.
The fact that it returns a pointer to an animation is the "efficiency". Look the pointer up when you need to change to a new animation since looking it up by name is the easiest way to do this. But then store the pointer and don't ask for it again until you need a different animation. Looking the animation up by pointer should be pretty efficient.
For those who don't know, the key frames are just poses of the armature (bones that control the model) with a specific frame number. So, if you have 90 frames in the animation and want to run the animation at 30 frames per second, the animation will last 3 seconds. And you may only get 7 key frames. Each key frame will have a frame number it needs to occur at. So for example, you may have the first one on the very first frame and then the second one on the 13th frame and the third on the 27th frame. All those frames in between you need to provide the poses for. So, between the first frame and the 13th frame - for example - you do a weighted average using SLERP to morph the pose of the first key frame into the pose of the 13th frame.