A survivor of fierce battles, foreign occupation and radical politics, the city of Shanghai is now engaged in an economic struggle that may test its genius and endurance more than any past ideological or shooting war.

China's largest city and leading industrial center is intensely proud of its accomplishments. But it is being told by the central government in Peking that it has lagged behind in implementing the country's recent economic reforms.

Shanghai, with a population of 12 million, weighs so heavily in the economy and politics of the nation and contributes such a talented work force in every field that Peking cannot let it go its own way.

The economic reforms currently under way in China involve moves away from Soviet-style centralized planning. They grant more decision-making authority to individual factories, which can now retain some of their profits and award higher bonuses to the most productive workers.

Those changes are the easy part for Shanghai. The more difficult reforms that Peking is looking for involve bringing a technological revolution to Shanghai.

This means accomplishing several difficult tasks simultaneously. The city must continue to produce the revenue that the central government depends on, while funding the modernization of its own antiquated industrial machinery (much of it 1950s and 1960s vintage). Shanghai must take better advantage of the experts in its numerous universities and scientific research institutes, many of whom have had little or no experience in applying their work to the real world of industrial production. In addition, the city is striving to become a major international trade and financial center.

Shanghai is clearly moving in these directions. The question is whether it is moving fast enough and effectively enough. Peking officials think Shanghai could do better -- much better.

China's economic reforms will not succeed or fail simply on the basis of what happens in Shanghai. But a failure in Shanghai, which includes many of the country's most highly educated citizens, would deal a major blow to China's reform plans.

The importance of the city in the overall scheme of reform in China is uncontested. Shanghai accounts for one-ninth of the country's total industrial output. Its revenues come to one-seventh of the national income, nearly all of that sent on, until recently at least, to the central government. The city's harbor handles more than a third of the nation's sea-going cargo. According to city officials, Shanghai's industrial and agricultural production increased 10 percent in 1984 from the previous year's production.

But that is still behind the 13.1 percent increase for the nation as a whole. Shanghai is not doing well enough, say some critics, for a city which is still the country's most important educational and scientific center.

China's Premier Zhao Ziyang flew here from Peking in December to set things straight in the city. Zhao told Shanghai officials that the next few years could possibly be the most difficult ones for the city. While acknowledging Shanghai's contribution to the nation, Zhao said that Shanghai faced "many practical problems." Its biggest problem, he said, would be an increase in the prices of energy and raw materials, which have been kept artificially low.

But one of Shanghai's vice mayors, Ruan Chongwu, later told the foreign consular corps that Zhao had shown considerable understanding for Shanghai's problems and had brought the city "gifts instead of whips."

According to Ruan, Shanghai was so important to the country that it was not expected to take the lead in economic reforms. It could not afford to make expensive mistakes, he said.

Ruan argued that, despite its slow start in the reform program, Shanghai is like a marathon runner. Even though overtaken by certain less experienced pacemakers at the early stages of the race, he said, it will move ahead at the end.

The central government has reached agreements with Shanghai that allow the city greater autonomy in making decisions and a larger budget for the development of its aging transport and communications facilities. According to banking officials, Shanghai is now able to retain close to 25 percent of its revenues for such purposes, an important change in a system which used to send nearly all those revenues to Peking.

Foreign diplomats say that the diversion of revenues in the past forced Shanghai to contribute more than was justified to the central government, making the city a kind of "milk cow" for the rest of the country, and thus incapable of launching the construction projects which one sees elsewhere. Peking currently booms with new construction; in contrast, a visitor sees little construction in Shanghai, except on the city's outskirts.

Peking and Shanghai natives have traditionally sniped at each other, with Peking residents sometimes describing their comrades in Shanghai as too smart for their own good. Shanghai citizens answer that Peking is full of small-minded bureaucrats. Despite their cramped living conditions, among the most crowded in China, most Shanghainese would apparently prefer to stay where they are, speaking their nearly incomprehensible dialect and enjoying the wider variety of music, clothing and foods which are often in short supply elsewhere in China.

Some observers say that Shanghai's leadership has blocked reform. Shanghai's Communist Party First Secretary Chen Guodeng, 74, is described by some as a reluctant reformer who has held up appointments of professionally qualified officials. Chen is to be replaced within the next few months by Rui Xingwen, an electrical engineer who is the national government's minister of urban and rural construction and environmental protection.

The city's mayor, Wang Daohan, 69, will also be retiring soon. He is to be replaced by Jiang Zemin, an engineer currently serving as minister of electrical industry.

When the newly designated mayor and first party secretary take office, all of the top city positions will be held by engineers, including the six all-important vice mayors.

But foreign residents of the city say that Shanghai's problems are so large and have been so long in the making that it would be wrong to blame the city's current leaders for many of the difficulties. Industrial consultant Tao Zuji said in an article in the Washington-based China Business Review at the end of last year that Shanghai's decline in international trade, for example, was a result of an "imbalanced stress" on the development of industry, to the exclusion of other sectors, which dates all the way back to 1949.

Some Shanghai citizens say in conversations that the incoming group of city officials may have new difficulties of their own. They say that some of the workers in the city, who were taught to look down on "stinking intellectuals" during the Cultural Revolution of 1966-76, resent the university-trained professionals who are now in charge of the city's administration and many of its factories. They say that at the middle and lower levels of government and industry there are still some workers and cadres who offer "passive resistance" to the economic reforms introduced by Deng Xiaoping, China's principal leader, and his colleagues.

In a recent interview, one of Shanghai's vice mayors, Li Zhaoji, an electrical engineer, defended Shanghai's record and disputed allegations that it had fallen behind. Li argued that carrying out reforms in the cities was a much more complicated matter than reforming the countryside, and that therefore more care had to be taken.

Li said that despite criticism that it had acted indecisively, Shanghai last year had actually made "several dozen decisions" relating to economic reform. "Reforms in the city have increased labor productivity and also efficiency . . . . The city has also increased its revenue," said Li in the interview. "So I can't really figure out where we are lagging behind compared with other cities and provinces."

According to Lu Mingjing, director of a Shanghai radio factory, he and his colleagues now have the authority to make more of their own decisions. Authority over production decisions was shifted to him and other professional managers and away from a Communist Party committee, he said.

Lu said that the managers had demoted or moved into retirement 10 cadres above the section chief level who were incompetent, poorly educated or past retirement age. Profits have risen, he said.

But the director said that should the factory want to compete for overseas sales, it would run into difficulties because of a lack of sufficient automation. As it is, he said, overseas sales are extremely limited. Lu said that some key parts, including integrated circuits, still had to be imported, mostly from Japan, rather than being produced locally.