ok this is a very vague question but makes for a fun conversation.
Generally the problem you are describing is not really a technical problem, but a business problem.
Some of the huge advantages of rails is speed for development, maintenance, etc. C and C++ are great tools as well, but it tends to take longer to build the same thing in C as it does in rails. This means it is more expensive.
This cost is ongoing.
With rails you will lose some performance which will require more hardware. This cost is ongoing.
Lets assume the complex algorithm is a long running function that can be defined as the following happening within a User class.
def DoIt()
sleep 10000
end
Now lets also assume that you need to have this happen for a lot of items at a time. Say 10000 users every minute.
If we were to do this in a straight linear process we would be looking at a run time of 10000*10000 every minute. That is no bueno.
Luckily these problems are solved all of the time.
What we are discussing becomes Vertical vs Horizontal scaling.
Vertical:
Lets assume that if you write it in c the function becomes the equivalent of:
def DoIt
sleep 5000
end
You have gained 50% and that is great. The problem is that if your user load grows you end up in trouble. We see this in production systems all the time.
So now the question is how can you horizontally scale this.
Using resque (or any of 100s of solutions for this) you can kick this work to background and distribute it.
You can then add servers to handle the load that comes into the system.
Now the question is, is it worth the cost of building it in c/c++ or are you better building it in rails and paying for the extra hardware? Or is it better to start with rails, and if needed move to c++/C when you have your prototype finished and validate that it is needed.