Shell Sort Test

Source: Internet
Author: User
Tags comparison table include printf sort strcmp

First, the comparison table:

The test results for the sequencing program mentioned in section I of chapter I are as follows:
┌──────┬─────────┬────────┐
│ Project │c│ combination language │
├──────┼─────────┼────────┤
│ source program length │1,363 bytes│3,581 bytes│
│ Executive Program length │69,345 bytes│803 bytes│
│ Programming Time │ 20-hour │ 80-hour │
│8,000 pen time │ 30 seconds │ 8 seconds │
│48,000 Pen │640kb in time, unable to perform │ 70 seconds │
└──────┴─────────┴────────┘

The combination language is flexible when used in a large amount of data processing, and the C language is limited by space and cannot be implemented with the current system space.
Test time: September 1989 12 to 18th.
Participants: Zhang Daquan, Chouguang, Li Chaohui.
Use machine: IBM ps/2-50,80286 Cpu,8mhz.
Use language: C and combination language.
Because other languages are not competent, so only choose the two.
Processing object: 48,000 Chinese phrases, taken from 12 files respectively.
There are 4,000 phrases per file.
Each phrase has one to five Chinese characters.
Each Chinese text occupies two characters inside the code.
All data accounted for 316,421 characters.
Sort by: Arrange by Cangjie letter.
For efficiency, the shell sort method is used.

Second, the production of combinatorial language:

1:CG SEGMENT
2:assume CS:CG,DS:CG,ES:CG
3:org 100H
4:start:
5:mov Ax,cs
6:mov Ds,ax
7:mov si,130; Point to input buffer
8:mov Bl,[si-2]
9:dec BX
10:sub BH,BH
11:mov [BX][SI],BH
12:cld
13:mov Dx,si
14:mov ax,3d00h
15:int 21H; Open source file
16:jnc Zstart
17:mov Dx,offset ZSTR1; If there is no such file, exit
18:mov ah,9
19:int 21H
20:int 20H
21:zstart:
22:mov Bx,ax
23:sub DX,DX
24:mov cx,8000h
25:mov bp,4d00h
26:mov DS,BP
27:zread:
28:mov ah,3fh; Read file
29:int 21H
30:or Ax,ax
31:JZ Zrend
32:mov Ax,ds; Not finished, change the paragraph again read
33:add ax,800h
34:mov Ds,ax
35:JMP Zread
36:zrend:
37:mov Ah,3eh; Close File
38:int 21H
39:mov ax,2400h
40:mov Es,ax
41:sub Di,di
42:sub Si,si
43:mov DS,BP
44:sub BP,BP
45:ZC1:
46:call zchgseg
47:mov cx,5; Change the unequal length to equal length
48:ZC3:
49:lodsw
50:CMP AL,0DH
51:JZ ZC4
52:stosw
53:loop ZC3
54:inc SI
55:inc SI
56:JMP Short ZC5
57:ZC4:
58:mov ax,2020h
59:rep STOSW
60:ZC5:
61:inc BP
62:lodsb
63:dec SI
64:CMP Al,1ah
65:JNZ ZC1
66:stosb
67:mov CS:ZBW2,BP; BP for data counting
68:call Zsort; Sort
69:call Zdel; Delete the same person
70:call ZTR; Change to an unequal way
71:mov SI,DX
72:sub CX,CX
73:push CS
74:pop DS
75:mov Dx,offset ZFCB; Archive the results
76:mov ah,3ch
77:int 21H
78:mov Bx,ax
79:mov ax,2400h
80:mov Ds,ax
81:sub DX,DX
82:or Si,si
83:JZ ZC7
84:mov cx,8000h
85:ZC6:
86:mov ah,40h
87:int 21H
88:mov Ax,ds
89:add ax,800h
90:mov Ds,ax
91:dec SI
92:JNZ ZC6
93:ZC7:
94:mov Cx,di
95:mov ah,40h
96:int 21H
97:mov Ah,3eh
98:int 21H
99:int 20H
100:zsort:; Sort a child program
101:shr bp,1
102:ZS0:
103:push BP
104:mov CS:ZBW1,BP
105:mov AX,CS:ZBW2
106:sub AX,BP
107:mov DX,BP
108:mov Bp,ax
109:mov di,2400h
110:mov Ds,di
111:sub Si,si
112:call Zfindes
113:add Bx,di
114:mov ES,BX
115:mov Di,ax
116:sub DX,DX
117:ZS1:
118:call Zcomps
119:jbe ZS4
120:call Zxchg
121:push DS
122:push ES
123:push SI
124:push DI
125:push DX
126:ZS2:
127:mov Di,si
128:mov Ax,ds
129:mov Es,ax
130:sub DX,CS:ZBW1
131:JC ZS3
132:call Zfindes
133:mov Si,ax
134:add bx,2400h
135:mov DS,BX
136:call Zcomps
137:jbe ZS3
138:call Zxchg
139:JMP ZS2
140:ZS3:
141:pop DX
142:pop DI
143:pop SI
144:pop ES
145:pop DS
146:ZS4:
147:add si,10
148:js ZS7
149:ZS5:
150:add di,10
151:js ZS8
152:ZS6:
153:inc DX
154:CMP DX,BP
155:JNZ ZS1
156:pop BP
157:shr bp,1
158:JNZ ZS0
159:ret
160:ZS7:
161:sub si,8000h
162:mov Ax,ds
163:add ax,800h
164:mov Ds,ax
165:JMP ZS5
166:ZS8:
167:sub di,8000h
168:mov Ax,es
169:add ax,800h
170:mov Es,ax
171:JMP ZS6
172:zfindes:
173:sub BX,BX
174:mov AX,DX
175:SHL ax,1
176:RCL bx,1
177:SHL ax,1
178:RCL bx,1
179:add AX,DX
180:ADC bx,0
181:SHL ax,1
182:RCL bx,1
183:push AX
184:mov cl,4
185:shr AX,CL
186:mov cl,12
187:SHL BX,CL
188:add Bx,ax
189:pop AX
190:and ax,15
191:ret
192:ZXCHG:
193:mov cl,5
194:ZXCHG1:
195:lodsw
196:mov Bx,es:[di]
197:stosw
198:mov [SI-2],BX
199:loop ZXCHG1
200:sub si,10
201:sub di,10
202:ret
203:zcomps:
204:mov cl,5
205:mov Ax,di
206:mov Bx,si
207:REPZ CMPSB
208:mov SI,BX
209:mov Di,ax
210:ret
211:ZTR:; To Swop equal length to an unequal string
212:mov ax,2400h
213:mov Ds,ax
214:mov Es,ax
215:sub Si,si
216:mov Di,si
217:mov BP,CS:ZBW2
218:mov Dx,si
219:ZTR1:
220:mov cl,5
221:lodsw
222:CMP ax,2020h
223:JNZ ZTR21
224:add si,8
225:dec BP
226:JMP ZTR1
227:ZTR2:
228:lodsw
229:CMP ax,2020h
230:JZ ZTR3
231:ZTR21:
232:stosw
233:ZTR3:
234:loop ZTR2
235:mov AX,0A0DH
236:stosw
237:dec BP
238:JZ ZTR4
239:call zchgseg
240:JMP ZTR1
241:ZTR4:
242:mov Al,1ah
243:stosb
244:ret
245:ZCHGSEG:; Change the program
246:or Si,si
247:jns ZCH1
248:sub SI,BX
249:mov Ax,ds
250:add ax,800h
251:mov Ds,ax
252:ZCH1:
253:or Di,di
254:jns ZCH2
255:sub DI,BX
256:mov Ax,es
257:add ax,800h
258:mov Es,ax
259:inc DX
260:ZCH2:
261:ret
262:zdel:; Delete the same string
263:mov ax,2400h
264:mov Ds,ax
265:mov Es,ax
266:sub Si,si
267:mov di,10
268:mov BP,CS:ZBW2
269:mov bx,8000h
270:zdel1:
271:dec BP
272:JZ ZCH2
273:mov Ax,si
274:push DI
275:mov cl,10
276:REPZ CMPSB
277:pop DI
278:mov Si,ax
279:JNZ ZDEL2
280:mov ax,2020h
281:mov [Si],ax
282:zdel2:
283:add si,10
284:add di,10
285:call zchgseg
286:JMP ZDEL1
287:ZBW1 DW 0
288:ZBW2 DW 0
289:ZFCB DB ' Yrrr ', 0
290:ZSTR1 DB ' FILE not FOUND!$ '
291:CG ENDS
292:end START

This program, the use of 80 hours, the source program is 3,581 characters, the executive program is 803 characters. Performs 48,000 phrase sorting, which takes 70 seconds.
And after, because the C language written program, can not handle 48,000 phrases, has been tried to 8,000, c to be competent. It takes only 8 seconds to test with a combination language program.

Third, the production process of C language:

In the same way, we use C to write the following program:
1: # include <fcntl.h>
2: # include <sys\stat.h>
3:
4:extern unsigned char yr[];
5:
6:main (argc, argv)
7:int argc;
8:char *argv[];
9: {
10:int i, N, fd, result;
11:long rsum;
12:unsigned Char *yrp[8000], *yrptr, eof[1];
13:
14:FD = open (argv[1], O_RDWR);
15:rsum = 0;
16:while ((result = Read (FD, &yr[rsum], 16384)) > 0)
17: {
18:rsum + = result;
19:printf ("%d%ld\n", result, rsum);
20:}
21:close (FD);
22:printf ("After reading file\n");
23:FD = creat (argv[1], S_iread | S_iwrite);
24:printf ("After creat file\n");
25:yrp[0] = Yrptr = yr;
26:n = 1;
27:while (*yrptr && n < 8000)
28: {
29:while (*yrptr++!= ' \ n ');
30:yrp[n++] = yrptr;
31:}
32:sort (YRP, N);
33:for (i = 0; i < n; i++)
34: {
35:yrptr = Yrp[i];
36:do
37: {
38:write (FD, yrptr, 1);
: while (*yrptr++!= ' \ n ');
40:}
41:eof[0] = 0x1a;
42:write (FD, EOF, 1);
43:close (FD);
44:}
45:
46:
47:sort (V, N)
48:unsigned Char *v[];
49:int N;
50: {
51:int Gap, I, J;
52:unsigned Char *temp;
53:
54:printf ("Enter sorting\n");
55:for (Gap = N/2 gap > 0; Gap/= 2)
56:for (i = gap; i < n; i++)
57:for (j = i-gap J >= 0; J-= Gap)
58: {
59:if (strcmp (V[j], v[j + gap)) <= 0)
60:break;
*:/* printf ("swapping\n");
62:temp = V[j];
63:V[J] = V[j + gap];
64:v[j + gap] = temp;
65:}
66:}
67:
68:STRCMP (v1, v2)
69:unsigned Char *v1, *v2;
70: {
:/* printf ("Enter strcmp\n");
72:for (; *v1 = = *v2; v1++, v2++)
73:if (*v1 = = ' \ n ')
74:return (0);
75:return (*v1-*V2);
76:}

This program is designed to be completed by the production, only 20 hours. But in the test, spent a lot of time, the most elaborate, always unable to make the program run, because the data is too large system space is not enough.
The last resort to delete the information to 8,000, only to run successfully, it takes 30 seconds.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.